2009/02/18 10:05 CodeIN/Web
크리에이티브 커먼즈 라이선스
Creative Commons License
It doesn't, because the onclick property of your HTMLElement object is
called as a method, and you've set it to a string value:

element.onclick = 'alert("something")'; // doesn't work

Your options include (but are not limited to):


1. element.setAttribute('onclick', 'alert("hi")');

2. function elClick() { alert('hi'); } // create a function object - put
this in your global scope to avoid closure memory leaks
....
// elsewhere...
element.onclick = elClick;

3.
element.onclick = new Function('alert("hi");');

DOM Table로 dynami 테이블을 생성할 때 event를 추가하는 방법이다.
posted by 조금까칠한남자