当前位置:编程学习 > JS >>

dom增加,删除,节点实例教程

dom移除节点代码

// 设置关闭和确定按钮的功能--关闭(移除)提示框      
              btnEnter.onclick=aClose.onclick=function(){
              document.body.removeChild(objId);
              document.body.removeChild(shadow);
              btnShow.disabled=false;

dom增加节点

 

     document.body.appendChild(shadow);
    obj.appendChild(divTitle);
    obj.appendChild(Container);
    obj.appendChild(msgBottom);
    document.body.appendChild(obj);

例子:

     var Btns=document.createElement("div");
    Btns.setAttribute("id","btns");
   
    var btnEnter=document.createElement("a");
    btnEnter.setAttribute("id","btnEnter");
    btnEnter.setAttribute("href","#1");
   
    var txtEnter=document.createTextNode("确定");
   
    btnEnter.appendChild(txtEnter);  
    Btns.appendChild(btnEnter);

js关闭层

var closeBar=document.createElement("div");
    closeBar.setAttribute("id","closebar");

    var A = document.createElement("a");
    /*
    以纯DOM的方法,我们这么写:
    var txtCloseWindow=document.createTextNode("关闭窗口");
    A.appendChild(txtCloseWindow);
    */
    A.innerHTML="关闭窗口";
    A.setAttribute("href","#1");
    A.setAttribute("id","btnClose");
    A.setAttribute("title","关闭窗口");
   
    closeBar.appendChild(A);

补充:网页制作,Dom教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,