简体   繁体   English

升级到jquery 1.10.2后,click事件不会触发

[英]click event doesn't fire after upgrading to jquery 1.10.2

I just upgraded from jquery 1.5.2 to 1.10.2. 我刚刚从jquery 1.5.2升级到1.10.2。 I changed all my .live() calls to .on(). 我将所有.live()调用更改为.on()。 But for some reason, one particular button is no longer working. 但由于某种原因,一个特定的按钮不再工作。 Here's the logic: 这是逻辑:

$("#add_to_rule").on("click", function()   {            
        console.log('inside add');
        //only add if no validation errors.
        if  ( ($('#contact_details').val().length == 0) ) {
            $('#validation_error').html("There is no information to add");
            return false;
        }
        var emess = $("#validation_error").text();
        if ( emess.length == 0 )  { 
                add_routing_entry();            
                update_call_routing_tag();      
        }
    });

It never prints the "inside add" message in the console. 它从不在控制台中打印“内部添加”消息。 From the console window, I've tested to make sure the element exists and returns the correct value. 从控制台窗口,我已经测试以确保元素存在并返回正确的值。 Here are some of the results from my tests inside the console: 以下是我在控制台内测试的一些结果:

$('#add_to_rule').val();
"Add to Rule"
$('#add_to_rule').on("click");
<input id=​"add_to_rule" type=​"button" class=​"submit" value=​"Add to Rule">​

I've also tried to change the value on the button as a test, from the console window like so: 我也尝试从控制台窗口更改按钮上的值作为测试,如下所示:

$('#add_to_rule').val("test");
[
<input id=​"add_to_rule" type=​"button" class=​"submit" value=​"test">​
]

And it does update the text on my button. 它确实更新了我按钮上的文字。

Finally, for what it's worth, I've dumped out the version of the jquery library it's picking up by adding the following line: 最后,为了它的价值,我通过添加以下行来删除它正在拾取的jquery库的版本:

console.log(jQuery.fn.jquery);

It prints 1.10.2. 它打印1.10.2。

Any suggestions on what I might be doing wrong would be appreciated. 任何有关我可能做错的建议都将受到赞赏。 Thanks. 谢谢。

将它绑定到最接近的静态父元素,使用这样的事件委托动态添加元素:

$(document).on("click","#add_to_rule", function()   {  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM