其他分享
首页 > 其他分享> > DOM操作自定义标签

DOM操作自定义标签

作者:互联网

创建标签然后对标签操作

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        abc{
            width: 20px;
            height: 20px;
            background-color: red;
            display: block;
        }
    </style>
</head>
<body>
<div id="box">
    <p id="child1">大壮</p>
</div>
<script type="text/javascript">
    var oDiv = document.getElementById('box');
    // var oP = document.createElement('abc');
    // oDiv.appendChild(oP);
    var op1 = document.getElementById('child1');
    var op2 = document.createElement('p');
    op2.innerText = '热狗';
    oDiv.insertBefore(op2, op1);

</script>
</body>
</html>

  

 

标签:oDiv,自定义,op2,DOM,标签,var,document,op1
来源: https://www.cnblogs.com/Alexephor/p/11347710.html