2009/02/18 10:05
CodeIN/Web
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):
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");');
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를 추가하는 방법이다.
'CodeIN > Web' 카테고리의 다른 글
| [javascript] confirm 사용법 (2) | 2009/03/01 |
|---|---|
| JavaScript String Replace All (3) | 2009/02/20 |
| [javascript] dynamic 테이블 생성시 event 추가 하는 방법 (0) | 2009/02/18 |
| [javascript] checkbox 활성화/비활성화 (0) | 2009/02/16 |
| [javascript] checkbox에 체크된 row만 삭제 하기 (0) | 2009/02/13 |
| [javascript] table에 row 추가 - insertRow() (0) | 2009/02/13 |


