Detecting value change of input[type=text] in jQuery

前端 未结 10 909
囚心锁ツ
囚心锁ツ 2020-12-04 07:04

I want to execute a function every time the value of a specific input box changes. It almost works with $(\'input\').keyup(function), but nothing happe

相关标签:
10条回答
  • 2020-12-04 07:41

    Try this:

    Basically, just account for each event:

    Html:

    <input id = "textbox" type = "text">
    

    Jquery:

    $("#textbox").keyup(function() { 
        alert($(this).val());  
    }); 
    
    $("#textbox").change(function() { 
    alert($(this).val());  
    }); 
    
    0 讨论(0)
  • 2020-12-04 07:41
    $("#myTextBox").on("change paste keyup select", function() {
         alert($(this).val());
    });
    

    select for browser suggestion

    0 讨论(0)
  • 2020-12-04 07:44

    just remenber that 'on' is recomended over the 'bind' function, so always try to use a event listener like this:

    $("#myTextBox").on("change paste keyup", function() {
       alert($(this).val()); 
    });
    
    0 讨论(0)
  • 2020-12-04 07:46

    you can also use textbox events -

    <input id="txt1" type="text" onchange="SetDefault($(this).val());" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
    
    function SetDefault(Text){
      alert(Text);
    }
    

    Try This

    0 讨论(0)
  • 2020-12-04 07:49

    Try this:

    $("input").bind({
                paste : function(){
                    $('#eventresult').text('paste behaviour detected!');
                }
    })
    
    0 讨论(0)
  • 2020-12-04 07:52

    Use this: https://github.com/gilamran/JQuery-Plugin-AnyChange

    It handles all the ways to change the input, including content menu (Using the mouse)

    0 讨论(0)
提交回复
热议问题