@change和bindinput互换 反正监控输入的值的
<input type="text" bindinput="onInputEvent" style="background-color: aqua;"/>
timer: null //声明 timer
onInputEvent(e) {
if (this.timer) {
clearTimeout(this.timer)
} // 每次进来的时候都将之前的清除掉,如果还没到 600毫秒(600毫秒自定义) 的时候就将之前的清除掉,这样就不会触发之前setTimeout绑定的事件, 如果超过 600豪秒,之前的事件就会被触发下次进来的时候同样清除之前的timer
this.timer = setTimeout(() => { //箭头函数 注意this
// 在这里进行我们的操作 这样就不会频繁的进行我们这里面的操作了
var value = e.detail.value;
var detail = {
"value": value
};
var options = {};
console.log(e.detail.value)
}, 600)
}
input输入只触发最后一次
最新推荐文章于 2024-08-28 16:28:30 发布
本文介绍了如何在JavaScript中使用`bindinput`和`onInputEvent`监控输入值的变化,并通过`setTimeout`和`clearTimeout`实现输入值的600毫秒延迟处理,防止频繁操作,提高性能。
1650

被折叠的 条评论
为什么被折叠?



