首页新闻找找看学习计划

这个代码可以帮我用jquery实现以下吗我想通过text里面的取值- +来做,指定要一个class:="jian",用文本做

0
[待解决问题]
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .hide{
            display: none;
        }
        .show{
            display: block;
        }
    </style>

</head>
<body>
<div>
    <div class="b-1">
       <div class="hang"> <span class="jian">-</span>aaa</div>
        <div class="show">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
    <div class="b-1">
        <div class="hang"> <span class="jian">-</span>aaa</div>
        <div class="show">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
    <div class="b-1">
        <div class="hang"> <span class="jian">+</span>aaa</div>
        <div class="hide">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
</div>
</body>
</html>

 

< >
分享
所有回答(1)
0
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $('.hang').on('click', function() {
                var status = $(this).find('.jian').text();
                if (status == '-') {
                    $(this).find('.jian').text('+');
                    $(this).next('div').addClass('show').removeClass('hide');
                } else {
                    $(this).find('.jian').text('-');
                    $(this).next('div').addClass('hide').removeClass('show');
                }
            })
        })
    </script>
    <style>
        .hide{
            display: none;
        }
        .show{
            display: block;
        }
    </style>

</head>
<body>
    <div>
        <div class="b-1">
         <div class="hang"> <span class="jian">-</span>aaa</div>
         <div class="hide">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
    <div class="b-1">
        <div class="hang"> <span class="jian">-</span>aaa</div>
        <div class="hide">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
    <div class="b-1">
        <div class="hang"> <span class="jian">+</span>aaa</div>
        <div class="show">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
</div>
</body>
</html>

 

RosonJ | 园豆:2439 (老鸟四级) | 2016-06-03 10:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册