当我的用户模糊或输入文本框时,我想触发一个功能。我编写了这段代码来实现它:
text:function(input,el){
var textCheck = function(){
var value = $.trim(el.val());
if(!value){
el.addClass('error');
}else{
el.removeClass('error');
}
}
$(el).on('blur click keyup', textCheck); //calling the function
$(el).on('keyup', function(e){ ////calling the function again
if(e.keyCode == 13){
textCheck();
}
});
//instead of calling 2 times, how can i put together as single call?
}
我可以缩短绑定事件的代码吗?