addClass实际上删除了我的代码中的类

时间:2016-02-05 07:38:46

标签: jquery

addClass("x")实际上删除了我的代码中的 “x”。使用调试器进行检查时,removeClass("x")无处调用。

这是我的代码,

$('.list-item > li:first-child').addClass('hide-lead');

任何人都有帮助!

3 个答案:

答案 0 :(得分:1)

您确定代码中没有任何额外的jquery脚本吗?

有一个代码示例,它的工作原理如下: https://jsfiddle.net/sebas07b/0bLLjojh/2/

我看不出任何错误。

答案 1 :(得分:1)

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<style>
    .hide-lead {
    color:red;
    }

</style>
<script>
    $(document).ready(function () {

        $('#add').click(function () {
            $('.list-item > li:first-child').addClass('hide-lead');
        });

        $('#remove').click(function () {
            $('.list-item > li:first-child').removeClass('hide-lead');
        });

    });
</script>
</head>
<body>
    <input type="button" value="Add Class" id="add" />
        <input type="button" value="Remove Class" id="remove" />
  <ul class="list-item">
      <li>hello1</li>
        <li>hello2</li> 
       <li>hello3</li>


  </ul>
</body>
</html>

答案 2 :(得分:0)

正如你们所说,我在我的代码中错误地调用了removeClass。经过长时间的斗争,发现removeClass隐藏在我的长jquery中。

相关问题