Fire oninput event with jQuery

前端 未结 7 913
太阳男子
太阳男子 2020-12-02 22:47

I have an oninput event on a textarea to check the height and resize it. Now I need to edit the value sometimes. I do this just by editting the val() in jQuery, but that doe

相关标签:
7条回答
  • 2020-12-02 23:21

    It is a bit too late, but for future reference, there is the .trigger method.

    $("#testArea").on("input", function(e) {
      $("#outputArea").text( $(e.target).val() )
    });
    
    $("#testArea").val("This is a test");
    $("#testArea").trigger("input");
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    
    <input id="testArea" type="text" />
    <div id="outputArea"></div>

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