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>

  • 相关阅读:
    Android开发学习总结(一)——搭建最新版本的Android开发环境
    数据库服务器编码,数据库编码,数据库表编码,数据库表字段编码
    webservice(二)简单实例
    webservice(一) 概念
    JAVA的StringBuffer类
    Log4J日志配置详解
    如何配置使用 Log4j
    使用MyBatis Generator自动创建代码
    Spring MVC POST中文乱码解决方案
    JSP开发中对jstl的引用方式(标签库引用)
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2147827.html
Copyright © 2011-2022 走看看