如果 checkBrowser
函数的结果是 old
,我想使用 jQuery 提交一个表单。
<form action="xxx" method="post">
...
<input id="iop" type="submit">
...
</form>
jQuery:
$("#iop").mousedown(function(e){
e.preventDefault();
var status=checkBrowser();
if(status=='old'){
$("#iop").submit();
}
});
我做了什么:
我调试了代码,它到达了 $("#iop").submit();
行,但没有任何反应。有什么想法吗?
最佳答案
您需要使用 submit()
在 <form>
不是<input>
元素。来自 docs :
The submit event is sent to an element when the user is attempting to submit a form. It can only be attached to elements
if(status=='old'){
$("form").submit();
}
或使用 .closest() 更具体 以获得最接近的匹配 form
向上遍历 DOM 树时提交按钮的元素:
if(status=='old'){
$(this).closest('form').submit();
}
关于javascript - 表单提交不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22346072/