javascript - 【解决了】jq tab切换问题?
PHPz
PHPz 2017-04-11 11:32:29
[JavaScript讨论组]

  $(".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();
});
PHPz
PHPz

学习是最好的投资!

全部回复(2)
怪我咯

换个思路

<ul class="test">
    <li class="one">
    ...
    ...
</ul>
<ul class="test">
    <li class="one">
    ...
    ...
</ul>
<ul class="test">
    <li class="one">
    ...
    ...
</ul>
$(".test li").click(function() {
        var className = $(this).attr('class');
        $("." + className).addClass('on');
});
阿神

给个简单的实现:

$(".test ul").on('click', 'li', function(){
        var _index = $(this).index();
        $(".test ul").find("li:eq(" + _index + ")").addClass('on').siblings().removeClass('on');
    })
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号