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>

  • 相关阅读:
    内存泄露之LeakCanary原理简析
    springboot(2.3.4)替换默认的logback为log4j2
    springboot-SPI-修改配置文件
    Vue组件
    米尔开发板测试记录
    调试米尔开发板记录
    linux操作GPIO命令
    linux操作PWM命令
    前端缓存(Storage)之有效期
    微信移动端判断二维码识别是否长按
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2147827.html
Copyright © 2011-2022 走看看