猿问

jq tab切换问题?

 $(".test li").click(function() {        var _index = $(this).index();
        $('.test li' + ":eq(" + _index + ")").addClass('on')
    });

//我想点击01 所有01都需要加上on
//代码需要如何修改 谢谢

//解决方案

$('.test .bd .item:first-child').show();

$(".test li").click(function() {

    var _index = $(this).index() + 1;

    var textLi = '.test li';

    $('.test li' + ":nth-child(" + _index + ")").addClass('on').siblings().removeClass('on');


     $('.test .bd .item' + ":nth-child(" + _index + ")").show().siblings().hide();

});


三国纷争
浏览 562回答 1
1回答

一只斗牛犬

换个思路<ul&nbsp;class="test">&nbsp;&nbsp;&nbsp;&nbsp;<li&nbsp;class="one"> &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;&nbsp;&nbsp;...</ul><ul&nbsp;class="test">&nbsp;&nbsp;&nbsp;&nbsp;<li&nbsp;class="one"> &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;&nbsp;&nbsp;...</ul><ul&nbsp;class="test">&nbsp;&nbsp;&nbsp;&nbsp;<li&nbsp;class="one"> &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;&nbsp;&nbsp;...</ul>$(".test&nbsp;li").click(function()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;className&nbsp;=&nbsp;$(this).attr('class'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$("."&nbsp;+&nbsp;className).addClass('on'); });
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答