How to use JQuery to detect value-changed event when user drag & drop text into textbox?

前端 未结 3 809
小鲜肉
小鲜肉 2021-01-03 14:53

I\'m using this jQuery code

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

to detect if user drag text somewhere into my input & change it

3条回答
  •  鱼传尺愫
    2021-01-03 15:35

    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;
    });
    

    run the code: http://jsfiddle.net/paulwesterberg/FJuvz/5/

提交回复
热议问题