无需传递任何内容。用于的函数
addEventListener将自动
this绑定到当前元素。只需
this在您的函数中使用:
productLineSelect.addEventListener('change', getSelection, false);function getSelection() { var value = this.options[this.selectedIndex].value; alert(value);}如果要将任意数据传递给函数,请将其包装在您自己的匿名函数调用中:
productLineSelect.addEventListener('change', function() { foo('bar');}, false);function foo(message) { alert(message);}如果你想设置的值
this手动,您可以使用该
call方法来调用该函数:
var self = this;productLineSelect.addEventListener('change', function() { getSelection.call(self); // This'll set the `this` value inside of `getSelection` to `self`}, false);function getSelection() { var value = this.options[this.selectedIndex].value; alert(value);}


