前端IOS今天需要动态的在图片前面添加一个按钮

主要是在使用 

  bt.setAttribute("class","aaa"); 

可以对创建的节点使用setAttribute添加属性。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        
        <style>
            .aaa{
                background-color: #333333;
                width: 200px;
                height: 200px;
            }
        </style>
        <script type="text/javascript">
            
            function f1(){
            var  con = document.getElementById('content');
            bt = document.createElement("button");
            bt.setAttribute("class","aaa");
            con.appendChild(bt);
            }
            
        </script>
        
    </head>
    <body>
        <div id="content" style="background-color: #FF0000;">
            Hello
        </div>
        <button onclick="f1()">测试</button>
    </body>
</html>

 

相关文章:

  • 2021-11-30
  • 2021-09-22
  • 2021-07-19
  • 2021-12-09
  • 2021-12-19
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-06-06
相关资源
相似解决方案