jquery .live()事件不适用于Firefox和IE [英] Jquery .live() event not working on Firefox and IE

查看:140
本文介绍了jquery .live()事件不适用于Firefox和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form class ='myform'> 
< input type ='text'name ='fruit'>
< / form>
< a href ='#'class ='formSubmit'>提交< / a>

我有jquery调用表单通过Enter提交或点击标签


$ b $

  $('a.formSubmit')。live('click',function(){
$('form.myform')。 submit();

return false;
});
$ b $('form.myform')。live('submit',function(){
//在这里的条件语句
});

所以问题是,我的jQuery脚本在除IE和FireFox以外的所有浏览器上工作正常。似乎.live()方法是原因。因为当我删除live()方法,只要点击()方法它将工作。现在我需要在live()方法上做,因为我将会使用新添加的元素和表单。有什么办法可以使它在Firefox和IE浏览器上工作?



谢谢!

解决方案 div>

http://api.jquery.com/on/

$ ('click','a.formSubmit',function(){
$('')
$ b $

  $('#not_dynamically_generated_pa​​rent' form.myform')。submit(); 

return false;
}); ('submit','form.myform',function(){
//这里的条件语句
});

$('#not_dynamically_generated_pa​​rent'


I have live events with submit and click:

<form class='myform'>
    <input type='text' name='fruit'>
</form>
<a href='#' class='formSubmit'>Submit</a>

I have jquery that calls the form to submit via Enter or clicking the tag

$('a.formSubmit').live('click', function(){
    $('form.myform').submit();

    return false;
});

$('form.myform').live('submit', function(){
    //conditional statements here
});

So the problem is, my jquery scripts works fine on all browsers except IE and FireFox. It seems that .live() method is the cause. because when i remove live() method and do it just click() method it will work. Now i need to do it on live() method cause i will be having functionality with newly appended elements and forms. Is there any way to make it work on Firefox and IE?

Thanks!

解决方案

http://api.jquery.com/on/

$('#not_dynamically_generated_parent').on('click','a.formSubmit', function(){
    $('form.myform').submit();

    return false;
});

$('#not_dynamically_generated_parent').on('submit','form.myform', function(){
    //conditional statements here
});

这篇关于jquery .live()事件不适用于Firefox和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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