未捕获的类型错误:无法设置 null 的属性(设置“值”)
您好,我需要帮助解决我网站上的这个java脚本问题,我阅读了堆栈溢出和谷歌上的所有帖子,但它似乎对我没有帮助。我收到错误Uncaught TypeError:无法设置null的属性(设置' value')
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<div class="elementor-element elementor-element-bc48325 elementor-align-center elementor-widget elementor-widget-button" data-id="bc48325" data-element_type="widget" data-widget_type="button.default">
<a href="#elementor-action%3Aaction%3Dpopup%3Aopen%26settings%3DeyJpZCI6IjExMzIiLCJ0b2dnbGUiOmZhbHNlfQ%3D%3D" class="elementor-button-link elementor-button elementor-size-sm" role="button" id="Social-media-manager">
<span class="elementor-button-text">Apply Now</span>
</a>
</div>
//Popup form
<form class="elementor-form" method="post" name="New Form">
<input type="hidden" name="post_id" value="1132"/>
<input type="hidden" name="form_id" value="2c8531ad"/>
<input type="hidden" name="referer_title" value="Careers" />
<input type="hidden" name="queried_id" value="1304"/>
<label for="form-field-name" class="elementor-field-label elementor-screen-only">Name</label>
<input size="1" type="text" name="form_fields[name]" id="form-field-name" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Name*" required="required" aria-required="true">
<label for="form-field-field_1fc9713" class="elementor-field-label elementor-screen-only">Job Title*</label>
<input size="1" type="text" name="form_fields[field_1fc9713]" id="form-field-field_1fc9713" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Job Title*" required="required" aria-required="true">
<label for="form-field-email" class="elementor-field-label elementor-screen-only">Email*</label>
<input size="1" type="email" name="form_fields[email]" id="form-field-email" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Email*" required="required" aria-required="true">
<label for="form-field-message" class="elementor-field-label elementor-screen-only">Message</label>
<textarea class="elementor-field-textual elementor-field elementor-size-sm" name="form_fields[message]" id="form-field-message" rows="4" placeholder="Message" required="required" aria-required="true"></textarea> </div>
<input type="file" name="form_fields[field_501fb76][]" id="form-field-field_501fb76" class="elementor-field elementor-size-sm elementor-upload-field" multiple="multiple">
<button type="submit" class="elementor-button elementor-size-sm">Apply now</button>
</form>
<script>
var Social_media_manager = document.getElementById('Social-media-manager');
Social_media_manager.onclick = function(){
document.getElementById('form-field-field_1fc9713').value = 'New value';
};
</script>
</body>
</html>
这是网站的简化代码。有一个名为“立即应用”的按钮,按下它将调用名为“新表单”的弹出表单。使用我的 JavaScript,我尝试自动填充“form-field-field_1fc9713”,但它总是返回此错误。网站是使用 elementor 在 WordPress 上制作的,我使用位于底部的自定义代码功能
Hello i need help on fixing this java script issue on my website i read all post on stack overflow and google but it doesn't seem to help me .I am getting error Uncaught TypeError: Cannot set properties of null (setting 'value')
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<div class="elementor-element elementor-element-bc48325 elementor-align-center elementor-widget elementor-widget-button" data-id="bc48325" data-element_type="widget" data-widget_type="button.default">
<a href="#elementor-action%3Aaction%3Dpopup%3Aopen%26settings%3DeyJpZCI6IjExMzIiLCJ0b2dnbGUiOmZhbHNlfQ%3D%3D" class="elementor-button-link elementor-button elementor-size-sm" role="button" id="Social-media-manager">
<span class="elementor-button-text">Apply Now</span>
</a>
</div>
//Popup form
<form class="elementor-form" method="post" name="New Form">
<input type="hidden" name="post_id" value="1132"/>
<input type="hidden" name="form_id" value="2c8531ad"/>
<input type="hidden" name="referer_title" value="Careers" />
<input type="hidden" name="queried_id" value="1304"/>
<label for="form-field-name" class="elementor-field-label elementor-screen-only">Name</label>
<input size="1" type="text" name="form_fields[name]" id="form-field-name" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Name*" required="required" aria-required="true">
<label for="form-field-field_1fc9713" class="elementor-field-label elementor-screen-only">Job Title*</label>
<input size="1" type="text" name="form_fields[field_1fc9713]" id="form-field-field_1fc9713" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Job Title*" required="required" aria-required="true">
<label for="form-field-email" class="elementor-field-label elementor-screen-only">Email*</label>
<input size="1" type="email" name="form_fields[email]" id="form-field-email" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Email*" required="required" aria-required="true">
<label for="form-field-message" class="elementor-field-label elementor-screen-only">Message</label>
<textarea class="elementor-field-textual elementor-field elementor-size-sm" name="form_fields[message]" id="form-field-message" rows="4" placeholder="Message" required="required" aria-required="true"></textarea> </div>
<input type="file" name="form_fields[field_501fb76][]" id="form-field-field_501fb76" class="elementor-field elementor-size-sm elementor-upload-field" multiple="multiple">
<button type="submit" class="elementor-button elementor-size-sm">Apply now</button>
</form>
<script>
var Social_media_manager = document.getElementById('Social-media-manager');
Social_media_manager.onclick = function(){
document.getElementById('form-field-field_1fc9713').value = 'New value';
};
</script>
</body>
</html>
this is simplified code of the website . There is a button called Apply now ones pressed it will call popup form called New form . with my JavaScript i am trying auto fill "form-field-field_1fc9713" but it always returns me this error . Website is made on WordPress using elementor and i am using custom code function placed at the bottom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将代码复制粘贴到 HTML 文件中,它将正常工作,并且输入将填充“新值”,您的问题是弹出表单。您在创建表单之前调用
并将返回 null。请在弹出窗口创建后调用此行
If You copy-paste your code to an HTML file it will work fine and the input will be populated with the 'new value' your problem is the popup form. you call
before form created and will return null. please call this line after popup creation