为什么jquery表单提交事件没有解雇? [英] Why Jquery form submit event not firing?

查看:73
本文介绍了为什么jquery表单提交事件没有解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过jQuery提交表单。我想让我的表单提交事件在jquery提交表单时被解雇。



但是当表单提交成功时,提交事件处理程序没有成功调用。



以下是代码:

 < html> 

< head>
< title>表单< / title>

< script src =../ common / jquery-1.6.2.min.js>< / script>
< script>
$('#testform')。submit(function(){
$ .post($(this).attr(action),$(this).serialize(),function(html ){
$(#menu)。html('< object> + html +'< / object>');
});
return false; //防止正常提交
});

< / script>

< / head>

< body>

< form id =testformaction =<%= getURL%> method =post>
<! - < input type =hiddenvalue =DocQrySetupname = form>
< input type =hiddenvalue =bdqdb1name = config> - >
< input type =hiddenvalue =testname = otherParams>
< / form>

< script language = javascript>
$('#testform')。submit();
< / script>

< div id =menustyle =position:relative; bottom:0; overflow:hidden;>
< / div>
< / body>

我搜索了所有论坛,但无法获得分辨率。

解决方案

当您运行第一个脚本时,表单不存在,因此您的事件处理程序无需附加任何内容。



无论是需要将该处理程序移动到表单之后还是将其包装在

  $(document).ready function(){
$('#testform')。submit(function(){
/ * your code * /
});
});


I am trying to submit a form through jquery. I want to get my form submit event get fired when jquery submits the form.

But when form is submitted successfully, submit event handler is not called successfully.

Below is the code :

<html>

<head>
<title>forms</title>

<script src="../common/jquery-1.6.2.min.js"></script>
<script>
$('#testform').submit(function() {
    $.post($(this).attr("action"), $(this).serialize(), function(html) {
        $("#menu").html('<object>'+html+'</object>');
    });
    return false; // prevent normal submit
});

</script> 

</head>

<body>

    <form id="testform" action="<%=getURL%>" method="post" >
        <!-- <input type="hidden" value="DocQrySetup" name=form>
        <input type="hidden" value="bdqdb1" name=config>-->
        <input type="hidden" value="test" name=otherParams>
    </form>

    <script language=javascript>
        $('#testform').submit();
    </script>

<div id="menu" style="position:relative; bottom: 0; overflow:hidden;">
</div>
</body>

I searched all the forums but was not able to get the resolution.

解决方案

The form doesn't exist when you run the first script so your event handler has nothing to attach to.

Either need to move that handler to after the form or wrap it in

$(document).ready(function() { 
    $('#testform').submit(function() {
        /* your code */
    });
});

这篇关于为什么jquery表单提交事件没有解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆