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

我有这个jsfiddle

它使用toggle事件 – 不要用toggle来配置 – jQuery版本设置为EDGE

它突然停止工作并移除了我想要的单元作为触发器,因为它显然恢复了切换 。

我找不到任何弃用标签等

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

如果我添加迁移模块我的jsFiddle然后工作 ,我在控制台中看到警告(由FrédéricHamidi发布的https://github.com/jquery/jquery-migrate/blob/master/warnings.md详细说明)

我看到Deprecate fn切换并发出24和Ticket#11786,但不是在我希望看到的地方。

我缺少什么,在哪里可以找到替代品和文件?

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

$('#tbl .xx').toggle( function() { $(this).siblings().each(function(){ var t = $(this).text(); $(this).html($('',{'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,因此它是重命名而不是删除

您可以在jQuery Migrate插件发出的警告列表中找到有关toggle()弃用的官方文档:

JQMIGRATE:不推荐使用jQuery.fn.toggle(handler,handler …)

原因: .toggle()方法有两种完全不同的含义。 使用.toggle()来显示或隐藏元素不受影响。 使用.toggle()作为专门的单击处理程序在1.8中已弃用,在1.9中已删除。

解决方案:重写依赖于$().toggle() ,使用jQuery Migrate插件的缩小生产版本来提供function,或者从插件的源代码中提取$().toggle()方法并将其用于应用程序。

现在在api.jquery.com上记录了jquery .toggle()的弃用 。 我在forum.jquery找到了一个很好的替代品,我现在正在使用它。 它很棒:)

 $.fn.toggleClick = function() { var functions = arguments, iteration = 0; return this.click(function() { functions[iteration].call(); iteration = (iteration + 1) % functions.length; }); } 

用法:

 $("#target").toggleClick(function() { alert( "First handler for .toggle() called." ); }, function() { alert( "Second handler for .toggle() called." ); }); 

编辑2014年8月6日:我重新考虑了原始代码,发现.apply不适合使用。 将其更改为.call,未传入args。

jQuery 1.9还不是最终的。 根据升级指南:

“目前,本指南是标准jQuery API文档的附录,这些页面可能无法描述1.9版本的行为。请在我们更新api.jquery.com上各个页面的文档时耐心等待,以反映1.9的变化。“

在这种情况下,我们还没有记录它。 你们这些人比我们快! 请在此处提交文档票据: http : //github.com/jquery/api.jquery.com

我使用的代码:

 $('#example').click(function() { isClicked=$(this).data('clicked'); if (isClicked) {isClicked=false;} else {isClicked=true;} $(this).data('clicked',isClicked); if(isClicked) { ...do stuff... } else { ...do stuff... } }); 

优化的代码(由mplungjan建议)是:

 $('#example').click(function() { $(this).data('clicked',!$(this).data('clicked')); if ($(this).data('clicked')) { ...do stuff... } else { ...do stuff... } });