文章出處

在js代碼中引入以下代碼,讓高版本的jquery兼容toggle事件。代碼如下:

/** * Replacement for toggle */jQuery.fn.toggle = function( fn, fn2 ) { // Don't mess with animation or css toggles if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) { return oldToggle.apply( this, arguments ); } // Save reference to arguments for access in closure var args = arguments, guid = fn.guid || jQuery.guid++, i = 0, toggler = function( event ) {  // Figure out which function to execute  var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;  jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );  // Make sure that clicks stop  event.preventDefault();  // and execute the function  return args[ lastToggle ].apply( this, arguments ) || false; }; // link all the functions, so any of them can unbind this click handler toggler.guid = guid; while ( i < args.length ) { args[ i++ ].guid = guid; } return this.click( toggler );};

以上就是jquery不支持toggle()高(新)版本的問題解決的資料,希望能幫助到大家,謝謝大家對本站的支持!


歡迎轉載:http://www.kanwencang.com/bangong/20161116/54030.html

文章列表


不含病毒。www.avast.com
全站熱搜
創作者介紹
創作者 大師兄 的頭像
大師兄

IT工程師數位筆記本

大師兄 發表在 痞客邦 留言(0) 人氣()