服务器之家

服务器之家 > 正文

jquery不支持toggle()高(新)版本的问题解决

时间:2021-03-03 16:47     来源/作者:jquery教程网

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
 * 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()高(新)版本的问题解决的资料,希望能帮助到大家,谢谢大家对本站的支持!

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部