[英]Pass 'this' using bind click event handler to another function
我有一个绑定事件,正想调用一个函数,但是我需要this
传递给函数:
$( 'input.require' ).bind('paste', null, function(e) {
if(!e.keyCode){
required(this);
}
});
这是我正在调用的函数,它可以与所有其他事件处理程序一起正常工作。
更新:添加setTimeout
使其工作。 这是可以做的还是有更好的方法?
function required(thisObj){
setTimeout(function () {
if($(thisObj).val() != ''){
$(thisObj).removeClass('input-yellow');
} else {
$(thisObj).addClass('input-yellow');
}
}, 100);
}
在要求中,您只需要参考它
function required(myOldThis){
//use myOldThis here
}
$( 'input.require' ).bind('paste', null, function(e) {
var myObj = $(this)[0];
if(!e.keyCode){
required(myObj);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.