使用 onclick 提交表单时出现问题
我在提交表单时遇到问题,我的代码如下:
<form method="get" action="<?=bloginfo('template_url');?>/contact.php" id="quickContactForm" onsubmit="return sendDetails();">
<h2>Request a callback:</h2>
<ul style="margin:10px">
<li style="list-style-type:none;">
<label>Name:</label>
<input name="name" id="name" type="text" style="margin-left:12px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Email:</label>
<input name="email" id="email" type="text" style="margin-left:14px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Mobile:</label>
<input name="mobile" id="mobile" type="text" style="margin-left:8px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Note:</label>
<input name="interest" id="interest" type="textarea" style="margin-left:20px; height:100px">
</li>
<li style="list-style-type:none;">
<a href="javascript: void(0)" onclick="document['quickContactForm'].submit()" class="">
<img src="<?=bloginfo('template_url');?>/images/btn_send.jpg" />
</a>
</li>
</ul>
</form>
上面的代码给了我一个错误: document.quickContactForm 未定义 我也尝试将标签更改为:
<a href="javascript: void(0)" onclick="$('#quickContactForm').submit()" class="">
<img src="<?=bloginfo('template_url');?>/images/btn_send.jpg" />
</a>
但这也给了我一个错误: $ is not定义
我做错了什么?
问候, 斯蒂芬
I'm having a problem submitting my form, my code is as follows:
<form method="get" action="<?=bloginfo('template_url');?>/contact.php" id="quickContactForm" onsubmit="return sendDetails();">
<h2>Request a callback:</h2>
<ul style="margin:10px">
<li style="list-style-type:none;">
<label>Name:</label>
<input name="name" id="name" type="text" style="margin-left:12px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Email:</label>
<input name="email" id="email" type="text" style="margin-left:14px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Mobile:</label>
<input name="mobile" id="mobile" type="text" style="margin-left:8px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Note:</label>
<input name="interest" id="interest" type="textarea" style="margin-left:20px; height:100px">
</li>
<li style="list-style-type:none;">
<a href="javascript: void(0)" onclick="document['quickContactForm'].submit()" class="">
<img src="<?=bloginfo('template_url');?>/images/btn_send.jpg" />
</a>
</li>
</ul>
</form>
The above code gives me an error: document.quickContactForm is undefined I've also tried changing the tag to:
<a href="javascript: void(0)" onclick="$('#quickContactForm').submit()" class="">
<img src="<?=bloginfo('template_url');?>/images/btn_send.jpg" />
</a>
but this gives me an error aswell: $ is not defined
What am I doing wrong ?
Regards,
Stephen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$
由 jQuery 等库使用,但它不是 JavaScript 的一部分。您是否包含针对 jQuery 文件的标签?$
is used by libraries such as jQuery, but it is not part of JavaScript. Are you including a tag targeting a jQuery file?尝试使用 document.getElementById("quickContactForm").submit();
Try using
document.getElementById("quickContactForm").submit();
除非您在表单对象上引用 ID,否则无法获取 ID:
document.forms.quickContactForm
。 (或者如果您使用document.getElementById('quickContactForm')
)You can't get an ID unless you reference it on the forms object:
document.forms.quickContactForm
. (Or if you usedocument.getElementById('quickContactForm')
)