zoukankan      html  css  js  c++  java
  • Create elements

    create element1:

        var anchorText=document.createTextNode("monoceros");
        var newAnchor = document.createElement("a");
        newAnchor.href="http://www.baidu.com";//给新建的超链接节点添加链接属性
        newAnchor.appendChild(anchorText);
        var parent=document.getElementById("starLinks");
        var newChild=parent.appendChild(newAnchor);
        
        <h1>Creating elements and test nodes</h1>
        <p id="starLinks">
            <a href="test1.htm">Sirius</a>       
        </p>


    create element2:
        var anchorText=document.createTextNode("monoceros");
        var newAnchor = document.createElement("a");
        newAnchor.href = "http://www.baidu.com";
        newAnchor.appendChild(anchorText);
        var existingAnchor=document.getElementById("sirius");
        var parent=existingAnchor.parentNode;
        var newChild=parent.insertBefore(newAnchor,existingAnchor);

        <h1>Creating elements and text nodes</h1>
        <p id="starLinks">
            <a id="sirius" href="test1.htm">Sirius</a>
        </p>

    create element3:
        var anchorText=document.createTextNode("monoceros");
        var newAnchor = document.createElement("a");
        newAnchor.href = "http://www.baidu.com";
        newAnchor.appendChild(anchorText);
        var existingAnchor=document.getElementById("sirius");
        var parent=existingAnchor.parentNode;
        var newChild=parent.replaceChild(newAnchor,existingAnchor);

        <h1>Creating elements and text nodes</h1>
        <p id="starLinks">
            <a id="sirius" href="test1.htm">Sirius</a>
        </p>

  • 相关阅读:
    Windows10下VirtualBox安装CentOS7网络配置:添加DNS
    Windows下LaTeX环境: SumatraPDF + notepad++/ST3
    Windows10 环境变量设置: "此环境变量太大"
    修改CMD字体后导致乱码的恢复方法
    nfs:server is not responding,still trying 原因与解决方案
    [GIT] 更新.repo目录
    linux网络栈相关
    linux mailbox模型
    虚拟机ping不通主机,主机能ping 通虚拟机问题解决
    pygame学习
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2147827.html
Copyright © 2011-2022 走看看