jquery if判断 要求单击当前元素是怎么做?

查看:103
本文介绍了jquery if判断 要求单击当前元素是怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

http://jsbin.com/rakukogitu/edit?html,js,output

    $(".has-ul:gt(0)").find("li:not(.has-h1)").hide();
    $(".has-ul").on("click",function(){
        if( $(".iconfont").hasClass("icon-top")){
            $(this).find("li:not(.has-h1)").hide();
            $(".icon-top").attr("class","iconfont icon-down");
        }else{
            $(this).find("li:not(.has-h1)").show();
            $(".icon-down").attr("class","iconfont icon-top");
        }
    });

如何在当前元素中只可以改变一个icon-top .
而不是下面2个元素中跟着改变icon-top.
请高手指点一下。
我思路越来越乱。

解决方案

要不要试试我这招?

$(".has-ul:gt(0)").find("li:not(.has-h1)").hide();
$(".has-ul").on("click",function(){
    $(this).find('.iconfont').toggleClass('icon-top').toggleClass('icon-down');
    $(this).find("li:not(.has-h1)").toggle();
});

demo在这,JSBIN

这篇关于jquery if判断 要求单击当前元素是怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆