input输入框实时监控 并实现延迟发起请求

来源:互联网 发布:linux查看arp表 编辑:程序博客网 时间:2024/05/21 01:52

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 //定义全局timerdelayRequest: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();



0 0
原创粉丝点击