开发者

Is there a way to programmatically click on a combobox item?

开发者 https://www.devze.com 2022-12-30 22:08 出处:网络
I\'ve been trying experiments with the following, but so far to no开发者_如何学编程 avail: sel = document.getElementById(\'myComboBox\')

I've been trying experiments with the following, but so far to no开发者_如何学编程 avail:

sel = document.getElementById('myComboBox')
sel.selectedIndex = 1;
sel.options[1].selected = true;
sel[1].click();

Thanks for the help!


Wait why would you write:

sel.options[1].selected = true;

and then in the very next line write

sel[1].click();

?? The element is not an array and can't be treated as one.

The "click" event might not be the best thing to handle anyway. Probably the "change" event on the select element itself would be more reliable.

0

精彩评论

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

关注公众号