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>

  • 相关阅读:
    Java服务器 dm Server
    POI
    系统程序员成长计划写得又快又好的秘诀(四)
    _stati64()获取文件信息
    系统程序员成长计划并发(一)(下)
    KJAVA虚拟机Hack笔记用GTK+实现绘图操作
    系统程序员成长计划写得又快又好的秘诀(六)
    系统程序员成长计划并发(一)(上)
    系统程序员成长计划并发(二)(上)
    系统程序员成长计划并发(二)(下)
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2147827.html
Copyright © 2011-2022 走看看