如何使用JQuery来检测用户拖动时的值变化事件将文本放入文本框? [英] How to use JQuery to detect value-changed event when user drag & drop text into textbox?
本文介绍了如何使用JQuery来检测用户拖动时的值变化事件将文本放入文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这个jQuery代码
I'm using this jQuery code
$('input').bind('change mouseup', ... )
以检测用户是否将文本拖到我的输入&改变它的价值。但这似乎不行。为什么它不工作,以及如何让它工作?
to detect if user drag text somewhere into my input & change it value. But that seems doesn't work. Why doesn't it work and how I can get it to work?
推荐答案
var inputField = $("input");
var oldValue = inputField.text();
inputField.bind("drop", function() {
//when the drop happens the input value will not be updated yet
//use a timeout to allow the input value to change.
setTimeout($.proxy(function() {
if (this.value !== oldValue) {
$(this).trigger('change');
}
}, this), 0);
});
$("input").bind("change", function() {
oldValue = this.value;
});
运行代码:
http://jsfiddle.net/paulwesterberg/FJuvz/5/
这篇关于如何使用JQuery来检测用户拖动时的值变化事件将文本放入文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文