mpl*_*jan 20 jquery deprecated
它使用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($('<input />',{'value' : t}));
});
},
function() {
$(this).siblings().each(function(){
var inp = $(this).find('input');
if (inp.length){
$(this).text(inp.val());
}
});
}
);
Run Code Online (Sandbox Code Playgroud)
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 );
};
Run Code Online (Sandbox Code Playgroud)
更新我问他们是否可以将代码保存为fn.toggler,因此它是重命名而不是删除
Ran*_*tka 13
现在在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;
});
}
Run Code Online (Sandbox Code Playgroud)
用法:
$("#target").toggleClick(function() {
alert( "First handler for .toggle() called." );
}, function() {
alert( "Second handler for .toggle() called." );
});
Run Code Online (Sandbox Code Playgroud)
编辑2014年8月6日:我重新考虑了原始代码,发现.apply不适合使用.将其更改为.call,未传入args.
您可以找到有关官方文件toggle()
的折旧在通过了jQuery插件迁移发出警告的名单:
JQMIGRATE:不推荐使用jQuery.fn.toggle(handler,handler ...)
原因:该方法有两种完全不同的含义
.toggle()
.使用.toggle()
显示或隐藏元素不受影响.使用的.toggle()
是专门的点击处理程序1.8已被废弃,并在1.9中删除.解决方案:重写依赖的代码
$().toggle()
,使用jQuery Migrate插件的缩小生产版本来提供功能,或者$().toggle()
从插件的源代码中提取方法并在应用程序中使用它.
归档时间: |
|
查看次数: |
7630 次 |
最近记录: |