JS对DOM的操作

版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!


恰饭广告




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>document</title>
    <style>
       body{
           font-size: 20px;
        }
    </style>
    <script>
    window.onload=function(){
        var city = document.getElementById("city");
        var AddBefore=document.getElementById("AddBefore");
        AddBefore.onclick=function(){
            var ChongQing =  document.createElement("li");
ChongQing.appendChild(document.createTextNode("ChongQing"));
            city.insertBefore(ChongQing, document.getElementById("CD"));
        }
        var AddAfter=document.getElementById("AddAfter");
        AddAfter.onclick=function(){
            var KunMing =  document.createElement("li");
            KunMing.appendChild(document.createTextNode("KunMing"));
            CD.parentNode.insertBefore(KunMing, CD.nextSibling);
        }
        var AddList=document.getElementById("AddList");
        AddList.onclick=function(){
            var GuangZhou=  document.createElement("li");
            GuangZhou.appendChild(document.createTextNode("广州"));
            var Element=document.getElementById("city");
            Element.appendChild(GuangZhou);
        }
    }
    </script>
</head>
<body>
    <p style="color:red">旅游城市:</p>
    <ul id="city">
        <li id="BJ">北京</li>
        <li>上海</li>
        <li id="CD">成都</li>
        <li>天津</li>
    </ul>
    <input type="button" id="AddBefore" value="在节点成都前插入" />
    <input type="button" id="AddAfter" value="在节点成都后插入" />
    <input type="button" id="AddList" value="在所有节点后插入" />
</body>
</html>  

原文链接:https://www.idaobin.com/archives/224.html

让我恰个饭吧.ヘ( ̄ω ̄ヘ)

支付宝 ——————- 微信
图片加载中图片加载中



恰饭广告

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

30 ÷ = 6