最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Programmatically firing the onchange event of an HTML select element - Stack Overflow

programmeradmin1浏览0评论

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 = true;

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 = true;
Share Improve this question asked Jan 3, 2011 at 0:22 TermanTerman 9835 gold badges17 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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)

  1. 暂无评论