开发者

not able to fire the attachEvent Listener Method

开发者 https://www.devze.com 2023-03-02 01:04 出处:网络
In the below Code I have add the event Listeners on Select Combox box, When I change the value the event Listeners are not fired,

In the below Code I have add the event Listeners on Select Combox box, When I change the value the event Listeners are not fired, I am using the IE6 Browser, so used attachEvent method to fire it.

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);

I am trying to achieve, when user the changes the value in the开发者_开发知识库 drop down the respective alert messages should be fired...


IE6 does not implement appending a text node to an option element- you must use theoption.text='string'.

Also, the IE event type must be prefaced with 'on' in the attachEvent method.

0

精彩评论

暂无评论...
验证码 换一张
取 消