input输入框实时监控 并实现延迟发起请求
实时监控input代码
autoWatch:function(){
var that=this;
var $ele=$(this.element);
$ele.on('input propertychange',function(){
//console.log($(this));
var oldValue=$(this).data('oldValue');
var newValue=$(this).val();
if(oldValue==newValue){
//console.log('oldValue==newValue');
that.show();
return false;
}else{
//that.requestData(newValue);
that.delayRequest(newValue,0);
}
})
}
延迟处理代码
var timer=false //定义全局timer
delayRequest:function(newValue,i){//延时请求处理
var that=this;
var j=10;
if(timer){
clearInterval(timer);
}
timer=setInterval(function(){
++i;
if(i==j){
console.log(i,j);
that.requestData(newValue);
clearInterval(timer);
}
},100);
}
i初始值为0 一秒后执行请求 调用that.requestData();