wild84
wild84
2017-09-11 08:53

通过append添加的按钮,再通过样式获取不到

  • js
  • append
  • jquery

代码如下:

 <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"> 
    <title>Bootstrap 实例 - 按钮标签</title>
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<button class="btn btn-default" type="button">按钮</button>
</div>
    <script>
        $(".btn").click(function(){
            $("div").append('<button class="alert" type="button">按钮</button>');
        })
        $(".alert").click(function(){
            alert(1);
        })
        </script>
</body>
</html>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答