Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改上的事件(<;选择>;_Javascript_Html Select_Mootools_Mootools Events - Fatal编程技术网

Javascript 更改上的事件(<;选择>;

Javascript 更改上的事件(<;选择>;,javascript,html-select,mootools,mootools-events,Javascript,Html Select,Mootools,Mootools Events,使用Mootools,如果在上附加更改事件侦听器,如何访问所选的选项。我想要的是实际的元素,而不仅仅是值 $('select').addEvent('change',function(event) { //?? }); 只需访问select元素(事件处理程序中的this对象)上的selectedIndex属性即可获得选项索引 // get the index of the selected option var index = this.selectedIndex; // get t

使用Mootools,如果在
上附加更改事件侦听器,如何访问所选的选项。我想要的是实际的元素,而不仅仅是值

$('select').addEvent('change',function(event) {
    //??
});

只需访问select元素(
事件处理程序中的this
对象)上的
selectedIndex
属性即可获得选项索引

// get the index of the selected option
var index = this.selectedIndex;

// get the option element
var opt   = this.options[index];

这两种方法中的任何一种都会起作用:

查找方式:子体中选定的伪选择器

this.getElement(':selected');
获取第一个选定值

this.getSelected()[0];
纯javascript,使用selectedIndex属性

this.options[this.selectedIndex];

event.target.id
是对象


event.target.value
新值是否可能是e.target?在这里猜测thoughevent.target只指向元素