jquery – fn.toggle(handler(eventObject),handler(eventObject)…)去哪里了?

前端之家收集整理的这篇文章主要介绍了jquery – fn.toggle(handler(eventObject),handler(eventObject)…)去哪里了?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有 this jsfiddle

使用toggle event – 不要与toggle – jQuery版本设置为EDGE

它突然停止工作,删除我想要的单元格作为触发器,因为它显然恢复到toggle

我找不到任何弃用标签

http://api.jquery.com/category/deprecated/给出了404

如果我添加Migrate模块,我的jsFiddle then works,我看到在控制台的警告(https://github.com/jquery/jquery-migrate/blob/master/warnings.md由FrédéricHamidi发布)

我看到Deprecate fn toggleissue 24Ticket #11786,但不是我会期望看到的地方。

我缺少什么,在哪里可以找到替换和文档?

注意:我了解弃用的原因,我只是找不到官方文档的弃用

$('#tbl .xx').toggle(
  function() {
    $(this).siblings().each(function(){
      var t = $(this).text();
      $(this).html($('<input />',{'value' : t}));
    });
  },function() {
    $(this).siblings().each(function(){
      var inp = $(this).find('input');
      if (inp.length){
        $(this).text(inp.val());
      }
    });
  }    
);

MIGRATE中的代码

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 );
  }
  migrateWarn("jQuery.fn.toggle(handler,handler...) is deprecated");
  // 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 );
};

更新我已经询问他们是否可以将代码保存为fn.toggler,因此它是重命名而不是删除

解决方法

您可以在 the list of warnings emitted by the jQuery Migrate plugin中找到有关 toggle()‘s deprecation的官方文档:

JQMIGRATE: jQuery.fn.toggle(handler,handler…) is deprecated

Cause: There are two completely different meanings for the .toggle()
method. The use of .toggle() to show or hide elements is not affected.
The use of .toggle() as a specialized click handler was deprecated in
1.8 and removed in 1.9.

Solution: Rewrite the code that depends on $().toggle(),use the
minified production version of the jQuery Migrate plugin to provide
the functionality,or extract the $().toggle() method from the plugin’s source and use it in the application.

原文链接:https://www.f2er.com/jquery/182886.html

猜你在找的jQuery相关文章