gpt4 book ai didi

javascript - 模糊触发Change事件

转载 作者:行者123 更新时间:2023-11-28 01:41:51 26 4
gpt4 key购买 nike

我有以下代码:

$('.subtle-input').live('blur', function() {
// this will fire all the time
});

$('.provider-rate-card input[type="text"]').live('change', function() {
// this will fire some of the time, only when value is changed.
});

如何确保每当 change 函数运行时,blur 函数change 函数之前发生发生?

最佳答案

看看这个 jsfiddle :

<div class="provider-rate-card">
<input class="subtle-input" type="text" />
</div>

$(function() {


//This closure is simply here because you will be using a global variable
//It helps prevent pollution of the global namespace, which is a good
//practice in Javascript.
(function() {
//defines the flag
var changed = false;

$('.subtle-input').on('blur', function() {
blurFunction(changeFunction);
});

$('.provider-rate-card input[type="text"]').on('change', function() {
//sets the flag
changed = true;
});

function blurFunction(func) {
//do something every time it blurs
console.log('blurred');

//you will provide this callback as a parameter (see above)
return func();
}

function changeFunction() {
//checks the flag
if(changed === true) {
//do something whenever the value changes
console.log('changed');

//reset
changed = false;
}
}
})();

});

关于javascript - 模糊触发Change事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20846461/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com