在< select>上更改活动 [英] Change event on <select>
本文介绍了在< select>上更改活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Mootools,如果我在< select>
上附加更改事件监听器,我该如何访问所选的选项。我想要实际的元素,而不仅仅是价值。
With Mootools, if I attach a change event listener on a<select>
how do I access the option that was selected. I would like the actual element and not just the value.
$('select').addEvent('change',function(event) {
//??
});
推荐答案
其中任何一个都可以使用:
Either of these will work:
查找者:后代选择的伪选择器
find by :selected pseudo selector in descendants
this.getElement(':selected');
获得首选价值
this.getSelected()[0];
纯javascript,使用selectedIndex属性
pure javascript, use the selectedIndex property
this.options[this.selectedIndex];
这篇关于在< select>上更改活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文