the event can not work; why can't i use it?
if i use nether code , it can work;
code:
img.attachEvent("onclick",alert("aa"));
div.appendChild(img);
spanWord = document.createElement("span");
spanWord.innerHTML="some text";
div.appendChild(spanWord);
do anybody know the reason?
img.onclick= function(){alert('aa')}
never did care for attachEvent.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Above you have used a function call as the second argument attachEvent
The second argument to attachEvent is a function...
img.attachEvent("onclick",function(){alert{"aa");});
> div.appendChild(img);
> div.innerHTML+="some text";
Peter
Loose coupling between chunks of JavaScript and event delegation must
not be your thing, eh? It is relatively frequently that I attach more
than one window.onload handler to initialize javascript pieces that
deal with different parts of the page.
Peter