0

As Jquery 1.9 deprecated live() function,So I have to change those to alternative on().

Everything seems fine.

In my project i am using almost >100 live() functions.They should work great if I go there each place and change to on().

Is there any efficiant way or script to use on() function,where ever i am using live() now ??

This would save lots of my time.

Please suggest any other options too.

Thank.

4

2 回答 2

2

您可以尝试使用jQuery migrate来检测和恢复在 jQuery 中已弃用并从 1.9 版开始删除的 API 或功能。

于 2013-05-06T06:32:58.690 回答
1

也许你可以稍微调整一下!

只需使用.live()您自己的函数扩展 jquery,该函数在内部指向.on().

    (function(jQuery) {
        // Store a reference to the original remove method.
        var originalOnMethod = jQuery.fn.on;

        // Define overriding method.
        jQuery.fn.live = function() {
            // event is bind for the elements added dynamically as well. 
            if(typeof arguments[0] == "string" && typeof arguments[1] == "function"){
                $(document).on(arguments[0], this.selector, arguments[1]);
            }else{//applied when proper live syntax is not followed and event will not fire for dynamically added elements  
                originalRemoveMethod.apply( this, arguments );
            }

        }
    })(jQuery);

我刚刚创建了这个函数并进行了测试,它可以工作,但你永远不知道它在哪里中断。如果它需要任何东西来凝结,请回复。谢谢!:-)

于 2013-05-06T07:48:51.020 回答