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 조금까칠한남자
2009/02/13 18:37 CodeIN/Web
크리에이티브 커먼즈 라이선스
Creative Commons License
동적으로 생성한 테이블에서 checkbox에 체크된 것만 삭제 하기 위한 소스이다.
이것도 동작하지 않는 소스이며, 단지 이해를 돕기 위한 것이다.

function delRow(){      
   var sTable = document.getElementById('sTable');
   var lastRow = sTable.rows.length;
  
   if(confirm("정말 삭제 하시겠습니까?]")){       
       for( var i=1 ; i < lastRow ; i++ ){
            // 가장 중요한 부분이다.
            // getElementsByTagName("tr")을 이용해서 tag가 "tr"인 모든 것들을 배열로 받는다.
            // for문을 돌면서 각 "tr"라인의 cells[0].firstChild가 check되어 있는지 확인
            // 체크가 되어 있다면 deleteRow를 이용해서 삭제 한다.
           if( document.getElementsByTagName("tr")[i].cells[0].firstChild.checked){
               sTable.deleteRow(i);
           }
       }       
   }   
   return;
}

<table id="sTable">
<tr>     
    <th><input type="checkbox"></th>                                             
    <th>휴일</th>
    <th>내용</th>     
    <th>수정</th>                                                                             
</tr>
<%
    int i=1;                 
    for(String key : ini.get(section).keySet()){
%>
  <tr id="tableLine">
    <td><input type="text" id="rdate" name="rdate" value="<%=key %>"></td>                     
    <td><input type="text" id="whichDay" value="<%=ini.get(section).fetch(key) %>"></td>
    <td><input type="button" id="modifyButton" name="modifyButton" value="수정"></td>                                         
    </tr>
<%         
    i++;
    }
%>
</table> 
<input type="button" id="removeButton" name="removeButton" value="삭제" onclick="delRow()">



posted by 조금까칠한남자
prev 1 next