日期:2014-05-16  浏览次数:20400 次

JS创建删除元素
<html> 
    <head> 
        <title>createElement() Example</title> 
        <script type="text/javascript"> 
            function createMessage() { 
			    var aa = document.getElementById('ulMenu');	
                var oP = document.createElement("li"); 
				oP.id="four"
				oP.setAttribute('class','codeDemomouseOnMenu');
				//在火狐下支持,IE下不支持
				//oP.setAttribute('onclick',"changeDiv('userTable');this.className='codeDemomouseOnMenu'");
				//oP.setAttribute('ondblclick',"changeDiv('userTable');this.className='codeDemomouseOnMenu'");
                var oText = document.createTextNode("全部用户明细"); 
				oP.appendChild(oText); 
				aa.appendChild(oP);
				oP.onclick = function() {
					changeDiv(divid,liid);
					this.className=classNm;
				}
				oP.ondblclick = function() {
				    changeDiv(divid,liid);
					this.className=classNm;
				}
           } 
		   function removeMessage() {    
		        var aa = document.getElementById('ulMenu');	
                var oP = document.getElementById('four');    
                aa.removeChild(oP);    
           }  
        </script> 
    </head> 
    <body>
	<ul class="codeDemoUL" id="ulMenu">
        <li id="one" class="codeDemomouseOnMenu" onclick="changeDiv('treeTable');this.className='codeDemomouseOnMenu'" ondblclick="changeDiv('treeTable');this.className='codeDemomouseOnMenu'"  >部门明细</li>
         <li id="two" class="codeDemomouseOutMenu" onclick="changeDiv('listTable');this.className='codeDemomouseOnMenu'"  ondblclick="changeDiv('listTable');this.className='codeDemomouseOnMenu'" >用户明细</li>
         <li id="three" class="codeDemomouseOutMenu" onclick="changeDiv('spanTable');this.className='codeDemomouseOnMenu'" ondblclick="changeDiv('spanTable');this.className='codeDemomouseOnMenu'" > 任务明细</li>
</ul>   
	    
		<a href="#" onclick="createMessage()">aaaaaa</a>
		<a href="#" onclick="removeMessage()">bbbbbb</a>
    </body> 
      
</html> 

?