我有一个 iframe 和一个表单。 Form的目标是iframe。当我提交表单时,结果页面应该加载到 iframe 中。我已附上以下代码:
<html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
function submitForm() {
$("form#testForm").submit(function(){
alert('hii')
});
}
</script>
</head>
<body>
<iframe name="testFrame" id="testFrame" frameborder="1" scrolling="no" width="500" height="200"></iframe>
<form name="testForm" id="testForm" action="http://www.yahoo.com" target="testFrame"> </form>
<button name="testBtn" value="submit" onclick="submitForm();">submit</button>
</body>
</html>
警报没有出现...请帮助我...
最佳答案
作为docs say ,如果您使用参数调用 jQuery 事件方法,它会添加一个事件处理程序而不是触发该事件。您需要在 submitForm
外部添加事件处理程序。
$(document).ready($("form#testForm").submit(function(){
alert('hii')
});
function submitForm() {
$("form#testForm").submit();
}
关于Jquery 表单提交()回调不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2584071/