change event of html hidden field

前端 未结 2 450
情话喂你
情话喂你 2020-12-10 00:14

I want to check the change of html hidden field using jquery and i tried for this but the change event did not worked.

Somebody has and idea how to handle this?

2条回答
  •  感情败类
    2020-12-10 01:01

    The change event doesn't fire when the value is programmatically changed, if it did it would cause infinite loops in many situations.

    If you need the event to fire, then trigger it when changing the value yourself using .change(), like this:

    $("#hiddenId").val("new value").change();
    

    .change() is a shortcut for .trigger("change") or, if you don't want that change event to bubble for some reason, then use .triggerHandler("change").

提交回复
热议问题