先上代码
const bfscrolltop = document.body.scrollTop;
document.getElementById('consultDes').addEventListener('focus', this.resetScoll, false)
document.getElementById('consultDes').addEventListener('blur', function() {
document.body.scrollTop = bfscrolltop
document.getElementById('consultDes').removeEventListener('focus', this.resetScoll, false)
clearInterval(timer);
}, false)
}
说明:
removeEventListener只能移除具名函数的监听,且方法名称后面不能带()
// 监听手机返回
window.addEventListener("popstate", goBack(), false);
function goBack () {
if (this.showSelectlist) {
this.showSelectlist = false
window.history.pushState("","","#");
window.location.href = window.location.origin + '/#/taskAdd'
}
console.log(window.location.href)
}
// 取消监听
window.removeEventListener("popstate", this.goBack, false);