JQ实现2个type点击后div切换

实现:

点击follower显示div1,点击engagemnet显示div2。可能有更好的循环显示的方法,不过我不是学js的。。。只能用比较笨的方法=0=

css:

#select_menu_type li.on,#select_menu_type li:hover{border:1px solid #ddd;border-bottom: 1px solid #fff;padding: 0;color: #505050;}

html:

<div id="select_menu_type">
    <ul>
        <li class="on" id="comparefollower"><?php echo Yii::t('manager', 'Follower'); ?></li>
        <li id="compareengagement"><?php echo Yii::t('manager', 'Engagement'); ?></li>
    </ul>
</div>
<div class="comparefollower">
    <label>1</label>
</div>
<div class="compareengagement">
    <label>2</label>
</div>

js:

<script>
    //初始化加载follower,隐藏engagement
    window.onload = function () {
        $(".compareengagement").hide();
        $("#compareengagement").removeClass("on");
        $(".comparefollower").show();
    };
    //点击跳转follower-div
    $("#comparefollower").click(function () {
        $(".compareengagement").hide();
        $("#compareengagement").removeClass("on");
        $(".comparefollower").show();
        $("#comparefollower").addClass("on");
    });
    //点击跳转engagement-div
    $("#compareengagement").click(function () {
        $(".comparefollower").hide();
        $("#comparefollower").removeClass("on");
        $(".compareengagement").show();
        $("#compareengagement").addClass("on");
    });
</script>


你可能感兴趣的:(JQ实现2个type点击后div切换)