【发布时间】:2013-01-13 08:38:25
【问题描述】:
使用toggle event - 不要与toggle 混淆 - jQuery 版本设置为 EDGE
它突然停止工作并删除了我想要作为触发器的单元格,因为它显然恢复为toggle。
我找不到任何弃用标签等
http://api.jquery.com/category/deprecated/ 给出 404
如果我将 Migrate 模块添加到我的 jsFiddle then works 并在控制台中看到警告(由 Frédéric Hamidi 发布的 https://github.com/jquery/jquery-migrate/blob/master/warnings.md 详细说明)
我看到了 Deprecate fn toggle 和 issue 24 和 Ticket #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 所以它是重命名而不是删除
【问题讨论】:
-
根据bugs.jquery.com中的ticket #11786,似乎toggle event已被弃用/弃用;但你是对的,我在toggle event 的页面上也看不到。我建议您在票证上添加评论。
-
我记得不久前听说过这个,很困惑,前端文档中似乎没有将它标记为已弃用。
-
为什么投反对票?让我感到惊讶的是,有些人有时间投反对票,却懒得说出原因。
标签: jquery deprecated