我正在尝试使<select>
的<option>
的JavaScript与其中的2项内容相匹配,但是一旦选中其中一项,我似乎就无法做任何事件。这里是我的代码:在JavaScript中选择选项html
var e1 = document.getElementById("#selector").option[0].text;
var e2 = document.getElementById("#selector").option[1].text;
var e3 = document.getElementById("#selector").option[2].text;
document.querySelector("e1").addEventListener("click", myInfo, false);
function myInfo(){
alert("Test");
}
<select id="selector">
<option value="" disabled="disabled" selected="selected">Select a layout</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
如果您使用[jQuery](http://jquery.com/)库,这会容易得多。这对你来说是一种选择吗? – GentlemanMax
你能告诉我们你想解决什么问题吗?此外,'document.querySelector(“e1”)'正在寻找一个元素'',而你可能 - 或者应该是 - 寻找'
没有抱歉,现在不在这里。只有html,css和javascript – Amar