How do I trigger an onChange event for a hidden field?

前端 未结 1 566
清歌不尽
清歌不尽 2021-01-13 06:51

I want to fire an onChange event for hidden field, Most of the forums I\'ve read suggests that onChange doesn\'t work for hidden fields, So is there a way around for that,

相关标签:
1条回答
  • 2021-01-13 07:23

    In jQuery, you could trigger a custom event:

    $("#hidden_input_id").trigger("special-change");
    

    And you can listen with:

    $("#hidden_input_id").on("special-change", function () {
    
    });
    

    DEMO: http://jsfiddle.net/byKak/

    Reference:

    • .trigger(): http://api.jquery.com/trigger/
    0 讨论(0)
提交回复
热议问题