注:Click事件不适用于动态添加的类

时间:2016-08-22 08:34:51

标签: jquery

$('div.input-player-close#player').click(function (event) { 
    if ($(".input-player-close").length) {
        $('div#player').removeAttr('class').addClass('input-player-plus');
        $('div#player p').html("Select the filename");
    }
});      

$('div.input-player-plus#player').click(function (event) {  
    if ($("div.input-player-plus").length > 0) {
        $('div#player').removeAttr('class').addClass('input-player-close');
        $('div#player p').html("Print the filename");
    }
});

以上应该做什么

<div class="input-player-plus" id="player">
  <p>Select the filename</p>
</div>

点击后

<div class="input-player-close" id="player">
  <p>Print the filename</p>
</div>

以上未能执行我的预期输出,在上面的代码中看起来没有问题,仍然在某处,我缺少的东西。

0 个答案:

没有答案