时间: 2020-11-24|42次围观|0 条评论

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="i1">
        <input type="button" value="+" onclick="add_1();" style="background-color: red">
        <input type="button" value="+" onclick="add_2()" style="background-color: yellow">
    </div>
    <script>
        function add_1(){
            var tag = "<p><input type='text' style='background-color:red' /></p>" ;
            document.getElementById('i1').insertAdjacentHTML('beforeEnd',tag);
        }
        function add_2(){
            var tag = document.createElement('input');
            tag.setAttribute('type','text')
            tag.style.backgroundColor ='yellow';
            var p1 = document.createElement('p');
            p1.appendChild(tag)
            document.getElementById('i1').appendChild(p1)
        }
    </script>
</body>
</html>

 

转载于:https://www.cnblogs.com/Charles9703/p/7436526.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/96545411

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《Dom-创建标签
   

还没有人抢沙发呢~