无法触发attachEvent侦听器方法
问题描述:
在下面的代码中,我在Select Combox框中添加事件侦听器, 当我更改值时事件侦听器未触发, 我正在使用IE6浏览器,因此使用attachEvent方法来解雇它。无法触发attachEvent侦听器方法
var td3 = document.createElement("TD")
td3.setAttribute('id','r1c3');
objSelect = document.createElement("SELECT")
objSelect.name="scuola"
objSelect.id="sc"
objSelect.attachEvent('change', function e(){alert("You moved your mouse over me!"); });
//objSelect.addEventListener('change',alertit,true);
var theOption=document.createElement("OPTION");
theText=document.createTextNode("Select");
theOption.appendChild(theText);
objSelect.appendChild(theOption);
td3.appendChild(objSelect);
var theOptiony=document.createElement("OPTION");
theTexty=document.createTextNode("Yes");
theOptiony.appendChild(theTexty);
objSelect.appendChild(theOptiony);
td3.appendChild(objSelect);
var theOptionN=document.createElement("OPTION");
theTextN=document.createTextNode("No");
theOptionN.appendChild(theTextN);
objSelect.appendChild(theOptionN);
td3.appendChild(objSelect);
我想实现,当用户更改在下拉各自的警报消息的价值应该被解雇......
答
IE6不执行追加文本节点的选择元素 - 您必须使用theoption.text ='string'。
此外,IE事件类型必须以attachEvent方法中的'on'开头。