当用户将文本拖放到文本框中时,如何使用JQuery检测值更改事件?

我正在使用这个jQuery代码

$('input').bind('change mouseup', ... ) 

检测用户是否将文本拖到我的输入中并更改其值。 但这似乎不起作用。 为什么它不起作用,我怎么能让它工作?

 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 1.10.1 – 我成功了…

 $('body').on('input paste drop', '#txt-some-id, function() { $('#btn-some-id').prop("disabled", $(this).val().length === 0); }); 

如果要使用它或触发更改事件,则可以使用少量超时的jQuery paste事件,直到粘贴该值。 试试这个

 $("input").bind('paste', function(e) { var $el = $(this); setTimeout(function() { //Here you can use the pasted value or trigger the text change event $el.trigger('change'); }, 100); });