首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >脚本不断窃取remove函数上的类

脚本不断窃取remove函数上的类
EN

Stack Overflow用户
提问于 2012-08-21 17:36:00
回答 1查看 45关注 0票数 1

由于功能原因,我有一个删除类的脚本,问题是它删除了所有的类,而不只是它应该删除的类。

HTML

代码语言:javascript
复制
  <ul id="slidecontrols" class="sc-nav">
  <li class="dont-remove">
     <a href="#one" class="user-management shadow1">User Management</a>
  </li>
  <li class="dont-remove">
    <a href="#two" class="asset-management shadow1">Asset Management</a>
  </li>
   <li class="dont-remove">
    <a href="#three" class="reporting shadow1">Reporting & Analytics</a>
  </li>
  </ul>

添加类.selected并删除类.selected以及"li“元素上的所有其他类的jQuery。

代码语言:javascript
复制
$(document).ready(function () {

//Set the initial state: highlight the first button...
$('#slidecontrols').find('li:eq(0)').addClass('selected');

//and hide all slides except the first one
$('#slides').find('> div:eq(0)').nextAll().hide();

//actions that apply on click of any of the buttons
$('#slidecontrols li').click(function (event) {

    //turn off the link so it doesn't try to jump down the page
    event.preventDefault();

    //un-highlight the buttons
    $('#slidecontrols li').removeClass();

    //hide all the slides
    $('#slides > div').hide();

    //highlight the current button
    $(this).addClass('selected');

    //get the index of the current button...
    var index = $('#slidecontrols li').index(this);

    //and use that index to show the corresponding slide
    $('#slides > div:eq(' + index + ')').show();

});

});

< /script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-21 17:37:39

jsBin demo

而不是:

代码语言:javascript
复制
$('#slidecontrols li').removeClass();

使用:

代码语言:javascript
复制
$('#slidecontrols li').removeClass('selected');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12052041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档