$(document).ready(function(){
var keyUpTime = 0;
var t = 0;
var executeAfterOneSecond = false;
$('#source').keyup(function(){
if(executeAfterOneSecond == false){
executeAfterOneSecond = true;
t = setTimeout(function(){
executeAfterOneSecond = false;
sendValue($('#source').val());
}, 600);
}
keyUpTime = $.now();
setTimeout(function(){
if($.now() - keyUpTime >= 200) {
clearTimeout(t);
executeAfterOneSecond = false;
sendValue($('#source').val());
}
},200);
});
});
<textarea id="source" name="text" wrap="soft" tabindex="0" dir="ltr" spellcheck="false" autocapitalize="off" autocomplete="off" autocorrect="off" style="box-sizing: border-box; overflow-y: hidden; overflow-x: auto; padding-right: 20px; " class="oggy-textarea">
</textarea>
好吧,我希望我的代码适用于 change(); [$('#source').change(function(){---});],不在 keyup() 上,但它没有。我尝试使用 bind() 但没有。怎么了?