我正在使用这个jQuery代码
$('input').bind('change mouseup', ... )
检测用户是否将文本拖到我的输入和放大器中改变它的价值。但这似乎不起作用。为什么它不起作用以及如何让它起作用?
答案 0 :(得分:7)
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;
});
答案 1 :(得分:2)
jQuery 1.10.1 - 我在这方面取得了成功...
$('body').on('input paste drop', '#txt-some-id, function() {
$('#btn-some-id').prop("disabled", $(this).val().length === 0);
});
答案 2 :(得分:1)
如果您想要使用它或触发更改事件,则可以使用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);
});