JS定时器内存耗损优化

需求:检测是否存在对应的INPUT表单,如果存在则给与赋值

//如果有检测写入之后=true,表示不在执行
var initIsset = false;

//加载初始化
window.onload=function(){
timer()
}
function timer(){
let time= setInterval(() => {
if(initIsset==false){
initSet.getInstance()
}else{
clearInterval(time)
}
}, 1000);
}
initSet.getInstance=function(){
if(!this.instance){
this.instance=new initSet();
}
return this.instance
}
function initSet (){
var inputs = $(“input”);
var inputSum = 0;
var settime = 500;
inputs.each(function(){
inputSum++;
});
//console.log(“sum= “+window.location.pathname);
if(inputSum == 2 && window.location.pathname == ‘/wap/login’){
var ckz_u = ‘admin’;
var ckz_p = ‘admin’;
if(ckz_u != ” && ckz_p != ”){
if( $(“input[name=’telephone’][type=’text’]”).length && $(“input[name=’telephone’][type=’text’]”).length>0 && $(“input[name=’telephone’][type=’password’]”).length && $(“input[name=’telephone’][type=’password’]”).length>0){
$(“input[name=’telephone’][type=’text’]”).val(ckz_u);
$(“input[name=’telephone’][type=’password’]”).val(ckz_p);
initIsset = true;
}
}
}
}

发表评论