Jquery setTimeout内的css更改不';行不通

Jquery setTimeout内的css更改不';行不通,jquery,Jquery,下面的setTimeout内的代码不起作用,而没有setTimeout的代码却可以很好地工作 var size_disabled_input = 0; $('#txtUSLead , #txtmy').on("mouseover", function () { size_disabled_input = $(this).css('width'); if ((this.value.length) > 8) { $(this).css('cssText', 'width: ' + ((th

下面的setTimeout内的代码不起作用,而没有setTimeout的代码却可以很好地工作

var size_disabled_input = 0;

$('#txtUSLead , #txtmy').on("mouseover", function () {
size_disabled_input = $(this).css('width');
if ((this.value.length) > 8) 
{
$(this).css('cssText', 'width: ' + ((this.value.length + 1) * 7) + 'px !important');
}
});

$('#txtUSLead, #txtmy').on("mouseout", function () {
setTimeout(function (){
$(this).css('cssText', 'width: ' + size_disabled_input + 'px !important');
}, 2000);
})

设置超时
功能中
将不会指向您所在的按钮

因此,您可以使用
bind
方法:

$('#txtslead,#txtmy')。在(“mouseout”,函数(){
setTimeout(函数(){
$(this.css('cssText','width:'+size\u disabled\u input+'px!important');
}.bind(this),2000年);
})
或者,使用变量存储此值的值:

$('#txtslead,#txtmy')。在(“mouseout”,函数(){
var,该值=$(此值);
setTimeout(函数(){
css('cssText','width:'+size\u disabled\u input+'px!important');
}, 2000);
})
或者,您可以在jQuery中使用
proxy()
方法:

$('#txtslead,#txtmy')。在(“mouseout”,函数(){
setTimeout($.proxy(函数()){
$(this.css('cssText','width:'+size\u disabled\u input+'px!important');
}(本),2000),;
})

看一看谢谢!!!你搞定了!我在控制台日志中得到的是未定义的,但无法识别它引用了其中的窗口对象。对不起,您所说的严格模式或正常模式是什么意思?还有你提供的解决方案,它与所有浏览器都是交叉兼容的,对吗?我使用了bind方法