我有多个表单,其中包含类型为submit的输入标记,在所有表单中都使用id=submit。
<form id='geek' method="post" action="#" role="form">
<input type="text" name="name" class="modal_input" id='name' placeholder="Only Alphabets Allowed" >
<input type="submit" name="submit" value="Submit" class="apply_button text-center center-block" id="submit" />
</form>第二种形式
<form id='geek1' method="post" action="#" role="form">
<input type="text" name="name" id='name' placeholder="Only Alphabets Allowed" >
<input type="submit" name="submit" value="Submit" class="apply_button text-center center-block" id="submit" />
</form>调用form1
$('#geek').validator();
$('#geek').on('submit', function (e) {
......
})
});表格2
$('#geek1').validator();
$('#geek').on('submit', function (e) {
......
})
});元素ID应该是唯一的,对于这种做法,我做错了吗?
发布于 2016-10-22 07:10:19
元素ID应该是唯一的,对于这种做法,我做错了吗?
是的,因为您在多个input元素上使用input。在多个元素上使用name="name"很好,但对多个元素使用id="name"并不好。
就表单而言,id="geek"和id="geek1"是不同的ID,因此没有问题。
请注意,您的"form 2“示例在一个地方使用#geek1,在另一个地方使用#geek,这可能不是您想要的。
话虽如此,对于这些表单,您真的需要ids吗?不如:
$(".common-class-on-the-forms").validator().on("submit", function() {
// Use `this` here to refer to the specific form that was submitted
});https://stackoverflow.com/questions/40189327
复制相似问题