最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于dom編程中 動態(tài)創(chuàng)建與刪除元素的使用

 更新時間:2013年04月17日 14:26:34   作者:  
本篇文章小編將為大家介紹,基于dom編程中動態(tài)創(chuàng)建與刪除元素的使用,有需要的朋友可以參考一下
復制代碼 代碼如下:

<html>
<head>
<script type="text/javascript">
    function test(){       
        //createElement()  創(chuàng)建一個指定標簽名的元素[比如:動態(tài)創(chuàng)建超鏈接]
        var createa=document.createElement("a");
        createa.id="a1";
        createa.innerText="連接到百度";
        createa.;
        //createa.color="green" ////添加顏色(不要忘記style屬性,不然沒有效果)
        createa.style.color="green"
        //添加默認位置--body 并且添加子節(jié)點
        //document.body.appendChild(createa);
        //放置指定位置
        document.getElementById("div1").appendChild(createa);
    }

    function test2(){
        //指定位置刪除節(jié)點removeChild()
        document.getElementById("div1").removeChild(document.getElementById("a1")); //id 名重復 js只取第一個
    }
</script>
</head>
<body>
<!--動態(tài)創(chuàng)建元素-->
<input type="button" value="創(chuàng)建一個a標簽" onclick="test()"/><br/>
<input type="button" value="刪除創(chuàng)建一個a標簽" onclick="test2()"/>
<div id="div1" style="width:400px;height:300px;border:1px solid silver">
</div>
</body>
</html>

復制代碼 代碼如下:

<html>
<head>
<script type="text/javascript">
    function test(){       
        //createElement()  創(chuàng)建一個指定標簽名的元素[比如:動態(tài)創(chuàng)建超鏈接]
        var createa=document.createElement("a");
        createa.id="a1";
        createa.innerText="連接到百度";
        createa.;
        //createa.color="green" ////添加顏色(不要忘記style屬性,不然沒有效果)
        createa.style.color="green"
        //添加默認位置--body 并且添加子節(jié)點
        //document.body.appendChild(createa);
        //放置指定位置
        $("div1").appendChild(createa);
    }

    function test2(){
        //指定位置刪除節(jié)點removeChild()
        $("div1").removeChild($("a1"));
    }
  //定義一個函數(shù) 返回給定id的對象
    function $(id){
        return document.getElementById(id);
    }
</script>
</head>
<body>
<!--動態(tài)創(chuàng)建元素-->
<input type="button" value="創(chuàng)建一個a標簽" onclick="test()"/><br/>
<input type="button" value="刪除創(chuàng)建一個a標簽" onclick="test2()"/>
<div id="div1" style="width:400px;height:300px;border:1px solid silver">
</div>
</body>
</html>

相關(guān)文章

最新評論

沅江市| 聂荣县| 陇南市| 阿拉善盟| 舒城县| 丰台区| 井研县| 建昌县| 贺州市| 麻江县| 长治县| 翁源县| 昌宁县| 伊金霍洛旗| 民县| 惠州市| 西畴县| 轮台县| 密云县| 湟源县| 乌拉特中旗| 闵行区| 杨浦区| 壶关县| 塘沽区| 浪卡子县| 林西县| 西藏| 华池县| 马龙县| 江陵县| 深州市| 蒙自县| 金坛市| 息烽县| 泗水县| 高雄市| 资中县| 东港市| 龙山县| 元朗区|