使用ajax提交表单时,多个表单可以共享同一个id吗?比如下面这样。
HTML:
<form id="myForm" action="/form" method="post">
Phone: <input type="text" name="phone" />
<input type="submit" value="Submit" />
</form>
...
<form id="myForm" action="/form" method="post">
Name: <input type="text" name="name" />
Comment: <textarea name="comment"></textarea>
<input type="submit" value="Submit Comment" />
</form>
脚本:
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
</script>