开发者

Programmatically firing the onchange event of an HTML select element

开发者 https://www.devze.com 2023-02-02 18:11 出处:网络
How can I fire the onchange event of an HTML Select element by code. The following only selects a list item but doesn\'t seem to fire the onchange event?

How can I fire the onchange event of an HTML Select element by code.

The following only selects a list item but doesn't seem to fire the onchange event?

options[index].selected = t开发者_高级运维rue;


If the event is hoked up directly via onchange, you can invoke the handler by calling that handler, like this:

mySelect.options[index].selected = true;
mySelect.onchange();

...if it's not rigged up that way, then different approaches are appropriate depending on how you're binding, and more information about how your onchange handler(s) are attached would help.

0

精彩评论

暂无评论...
验证码 换一张
取 消