jquery不支持toggle()高(新)版本的问题解决
程序员文章站
2024-04-02 14:04:58
在js代码中引入以下代码,让高版本的jquery兼容toggle事件。代码如下:
/**
* replacement for toggle
*/
jqu...
在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()高(新)版本的问题解决的资料,希望能帮助到大家,谢谢大家对本站的支持!