如何通过bind将值传递给keyup函数?
我希望能够知道它是键入的文本还是粘贴的文本。
var a;
$(document).on("keyup", ".tfs", function() {
if(a != "paste text"){ //To show that it was not via paste
a = "type text"; // if not pasted keep value "type text"
}
})
$('.tfs').on('paste', function() {
a = "paste text"; // if pasted pass value "paste text"
});
修改
这与我的问题有关,但我不确定如何在我的代码中实现它。 https://api.jquery.com/on/(滚动到:将数据传递给处理程序)
答案 0 :(得分:0)
您可以使用blur
事件:
var a;
$(document).on("blur", ".tfs", function () {
console.log(a);
if (a != "paste text") { //To show that it was not via paste
a = "type text"; // if not pasted keep value "type text"
} else {
a = 'type text'; // Resetting
}
});
$('.tfs').on('paste', function () {
a = "paste text";
});