0

Jquery 1.9の非推奨live()関数として、それらを代替に変更する必要がありますon()

すべて問題ないようです。

私のプロジェクトでは、ほぼ 100 を超える関数を使用しています。live()それぞれの場所に移動して に変更すると、うまく機能するはずon()です。

私が今使っているところに、効率的な方法や機能scriptを使用する方法はありますか??on()live()

これにより、多くの時間を節約できます。

他のオプションも提案してください。

感謝。

4

2 に答える 2

1

これを少し微調整できるかもしれません!

jquery.live()を内部的に指す独自の関数で拡張するだけ.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 に答える