用户拖动时如何使用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屋!
查看全文