jquery添加的addClass添加点击事件,也用on绑定了click,还是没有效果
$('.toolbar .switch').click(function(){
     $('.toolbar .switch').toggleClass('chevron-left');
     $('.toolbar .switch').toggleClass('th-list');
})
$('.toolbar .switch').on('click','.chevron-left',function(){
alert()
});
$('.toolbar .switch').on('click','.th-list',function(){
alert()
})

解决方案 »

  1.   

    谁来帮忙解决一下呀,用的这个版本jquery-1.11.3.min.js
      

  2.   

    $('.toolbar .switch').on
    改为
    $('.toolbar').onon参数有选择器的话$要选出父对象,而不是本身
      

  3.   

    既然是jquery添加的addClass那么添加的点击事件也要同时写在添加此class的function内
    e.g.:<!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="x5-orientation"content="portrait">
    <title></title>
    <style>

    </style>
    </head>
    <body>
    <div>1234</div>
    <input type="button" value="点击"/>
    <script src="./jquery-1.11.3.min.js"></script>
    <script>
    $(function(){
    $("input").click(function(){
    $("div").addClass("newClass");
    $(".newClass").unbind('click').on('click',function(){
    alert("hello?");
    });
    });
    });

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