zoukankan      html  css  js  c++  java
  • 元素创建的三种方式

    <!--元素创建的三种方式-->
    <!--1.document.write("标签的代码及内容")-->
    <!--2.对象.innerHTML="标签及代码"-->
    <!--3.document.createElement("标签的名字")-->
    <script src="commer.js"></script>

    <!--<input type="button" value="设置" id="wr"/>-->
    <!--悄悄是离别的笙箫,沉默是今晚的康桥!-->
    <script>
    //document.write("标签的代码及内容")
    // ver("wr").onclick=function () {
    // document.write("<p>这是一个P</p>");
    // };
    //document.write 缺陷:如果是在页面加载完毕后,此时通过这种方式创建元素,那么页面上存在的所有内容全部被干掉
    </script>



    <!--<input type="button" value="点击" id="inn"/>-->
    <!--<div id="dv"></div>-->
    <script>
    // //对象.innerHTML="标签及代码"
    // ver("inn").onclick=function () {
    // ver("dv").innerHTML="<p>让暴风雨来得更猛烈些吧</p>";
    // };
    </script>


    <input type="button" value="创建" id="cj"/>
    <div id="xx"></div>
    <script>
    // // document.createElement("标签的名字")
    ver("cj").onclick=function () { //创建一个对象
    var pObj=document.createElement("P"); //document.createElement("标签的名字");对象
    setInnerText(pObj,"这是一个p");//把创建后的子元素追加到父级元素中
    ver("xx").appendChild(pObj);//append Child:追加 子元素
    };
    </script>
  • 相关阅读:
    shell test用法
    Makefile debug的经验
    Makefile 中:= ?= += =的区别
    Makefile中常用的函数
    Makefile选项CFLAGS,LDFLAGS,LIBS
    makefile双冒号规则
    makefile中的伪目标,强制目标和双冒号规则
    makefile 使用环境变量
    linux shell if语句使用方法
    linux的test命令
  • 原文地址:https://www.cnblogs.com/lujieting/p/10046547.html
Copyright © 2011-2022 走看看