单击“打开”窗口以在跨度上添加课程

时间:2018-10-04 10:52:41

标签: javascript html css

当我单击“打开”按钮时,我可以删除课程。我需要在单击按钮并单击窗口上的跨度显示后再次添加删除类

我的HTML文件

<button>Click To show Comment</button>
<span class="my_comment my_comment_none">Hello</span>

我的CSS文件

.my_comment{display: block} .my_comment_none{display: none}

我的js文件

$(document).ready(function () {
   $("button").click(function () {
      $(this).removeClass("my_comment_none");
    });
});

4 个答案:

答案 0 :(得分:2)

您可以在document对象上附加click事件,并检查目标名称以隐藏或显示注释:

$(document).ready(function () {
   $(document).click(function (e) {
      if($(e.target).is('BUTTON'))
        $('.my_comment').show();   
      else
        $('.my_comment').hide();
    });
});
.my_comment{display: none}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <div>Click on the button to show the comment 
  and hide the comment on clicking anywhere else</div>
  <button>Click To show Comment</button>
<span class="my_comment" id="comment">Hello</span>

答案 1 :(得分:1)

使用toggleClass

 $(document).ready(function () {
        $("button").click(function () {
            $(this).toggleClass("my_comment_none");
        });
    });

对于窗口,请单击。维护按钮的唯一ID,并使用ID为选择器的

$(window).click(function () {
    if ($('button').hasClass("my_comment_none")) {
        $('button').removeClass("my_comment_none");
    }
})

;

答案 2 :(得分:0)

使用toggleClass

   $(document).ready(function () {
       $("button").click(function () {
          $(this).toggleClass("my_comment_none");
        });
    });

答案 3 :(得分:0)

您可以仅使用jQuery slideToggle()函数。

df1[Result] = 'Pass'
df2[Result] = 'Fail'...
pd.concat([df1,df2,...all conditioned columns frames])
$("button").click(function(){
    $(".toggle").slideToggle();
})