我无法获得提交表单,提交中的alert ($('#submit').val());
,因此代码进入正确的位置,但表单未提交。JQuery函数提交()不提交表格
表单有一个其他名称的id,提交按钮被称为名称和ID保存在一个点上,目前都设置为提交。
任何帮助表示赞赏。
$(document).ready(function(){
// force content into cnamex
$('#submit').click(function(event){
event.preventDefault(); // prevent submit
error = '';
for (var i = 0; i < 10; i++) {
if ($('#cname' + i).length > 0) {
if ($('#cname' + i).val().length == 0) {
error = 'Names for those attending are required';
}
}
}
if (error != '') {
alert (error);
}
else {
$('#othernames').submit();
alert ($('#submit').val());
}
});
});
HTML生成PHP,这是一个版本,它没有任何盒验证
<form enctype="multipart/form-data" name="othernames" id="othernames" method="post" action="" target="_self">
<div class="table">
<table width="100%" border="0">
<tr>
<td colspan="3" ><input name="submit" id="submit" type="submit" value="Confirm Order" ></td>
</tr>
</table>
</div>
</form>
这是场验证: -
<form enctype="multipart/form-data" name="othernames" id="othernames" method="post" action="" target="_self">
<div class="table">
<table width="100%" border="0"><caption>Enter names for tickets, (if any)</caption>
<tr>
<th scope="col">Name</th>
<th scope="col">Email (Optional)</th>
<th scope="col">Club</th>
</tr><tr><td><input name="cID[]" type="hidden" value="11"><input name="cname[]" id ="cname0" type="text" size="15" maxlength="20"></td>
<td><input name="cemail[]" id="cemail0" type="text" size="15" maxlength="60"></td><td><input name="cclub[]" type="text" size="15" maxlength="25" value="VRA - United Kingdom"></td></tr><tr><td><input name="cID[]" type="hidden" value="11"><input name="cname[]" id="cname1" type="text" size="15" maxlength="20"></td>
<td><input name="cemail[]" id="cemail1" type="text" size="15" maxlength="60"></td><td><input name="cclub[]" type="text" size="15" maxlength="25" value="VRA - United Kingdom"></td></tr>
<tr>
<td colspan="3" ><input name="submit" id="submit" type="submit" value="Confirm Order" ></td>
</tr>
</table>
</div>
</form>
问题使用reyaner的建议解决, 谢谢。现在JQuery的读取和HTML使用一个提交按钮
$(document).ready(function(){
// force content into cnamex
$('#submit').click(function(event){
error = '';
for (var i = 0; i < 10; i++) {
if ($('#cname' + i).length > 0) {
if ($('#cname' + i).val().length == 0) {
event.preventDefault(); // prevent submit
error = 'Names for those attending are required';
}
}
}
if (error != '') {
alert (error);
}
});
});
enter code here
你能告诉你的HTML –
你应该试试:'$(本).closest( '形式')得到(0).submit( );'顺便说一下,ID在上下文页面上必须是唯一的 –
而不是提交提交按钮,然后使用'event.preventDefault();'来停止默认功能,为什么不简单地使用常规按钮并添加此功能? – Nunners