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 조금까칠한남자
2008/11/24 16:03 Voice Portal/Dialog Designer
크리에이티브 커먼즈 라이선스
Creative Commons License
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package common;

import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

/**
 *
 * @author Administrator
 */
public class SetXML {
        
    public SetXML(){
    try {
            /////////////////////////////
            //Creating an empty XML Document

            //We need a Document
            DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
            Document doc = docBuilder.newDocument();

            ////////////////////////
            //Creating the XML tree

            //create the root element and add it to the document
            Element root = doc.createElement("root");            
            doc.appendChild(root);

            //create a comment and put it in the root element
            Comment comment = doc.createComment("Just a thought");
            root.appendChild(comment);

            //create child element, add an attribute, and add to root
            Element child = doc.createElement("child");
            child.setAttribute("name", "value");
            root.appendChild(child);

            //add a text element to the child
            Text text = doc.createTextNode("Filler, ... I could have had a foo!");
            child.appendChild(text);

            /////////////////
            //Output the XML

            //set up a transformer
            TransformerFactory transfac = TransformerFactory.newInstance();
            Transformer trans = transfac.newTransformer();
            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            trans.setOutputProperty(OutputKeys.INDENT, "yes");

            //create string from xml tree
            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(doc);
            trans.transform(source, result);
            String xmlString = sw.toString();

            //print xml
            System.out.println("Here's the xml:\n\n" + xmlString);

        } catch (Exception e) {
            System.out.println(e);
        }
    }       
}

'Voice Portal > Dialog Designer' 카테고리의 다른 글

/conf/Catalina/localhost의 xml파일  (0) 2008/11/26
[xml]XML 파일 읽어오기  (0) 2008/11/24
XML 관련 심플 예제  (0) 2008/11/24
VoiceXML이란  (0) 2008/11/14
[SVN] Section header expected  (0) 2008/11/08
[SVN] Option expected  (4) 2008/11/08
posted by 조금까칠한남자
TAG DOM, Java, JDOM
prev 1 next