Fire oninput event with jQuery

前端 未结 7 951
太阳男子
太阳男子 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 22:58

    You can simply invoke it, e.g.:

    $("input")[0].oninput = function () {
       alert("hello"); 
    };
    
    $("input")[0].oninput();
    

    ...but as @Sammaye points out, jQuery has no explicit "oninput" handler, so you'll have to use POJS.

    Demo on JS Fiddle.

提交回复
热议问题