在传统的添加事件监听器的方法中:
function getComboA(sel) {
var value = sel.options[sel.selectedIndex].value;
}
<select id="comboA" onchange="getComboA(this)">
<option value="">Select combo</option>
<option value="Value1">Text1</option>
<option value="Value2">Text2</option>
<option value="Value3">Text3</option>
</select>
但是我想要适应使用addEventListener
的方式:
productLineSelect.addEventListener('change',getSelection(this),false);
function getSelection(sel){
var value = sel.options[sel.selectedIndex].value;
alert(value);
}
为什么我不能在addEventListener
方法中传递参数给getSelection()
作为第二个参数呢?据我所知,我只能使用函数名称而不需要括号。
有什么想法吗?
顺便提一下,请看看我的以前的问题,关于console.log
无法在Safari 6.0开发人员检查器中输出,这让我很沮丧。