JQuery点击元素显示出来内容

2019-04-04  本文已影响0人  江边有颗桃

我需要注意什么:
1.text-indent属性是控制文本缩进的,但是设置属性值为负值时,文本向左侧缩进,当负值过小时,文本就会看不见,从而也就达到了隐藏的效果

2.(this).index()基于this同级所有元素的下标;('div').index(this),返回的是this在jquery对象div集合中的下标从0开始;

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>点击事件</title>
    <style type="text/css">
    div {
        float: left;
        margin: 10px;
        width: 100px;
        height: 100px;
        color: #fff;
        font-size: 50px;
        text-align: center;
        line-height: 100px;
        text-indent: -9999px;
        background-color: #333;
    }
    </style>
</head>

<body>
    <h1>添加事件处理</h1>
    <div>43</div>
    <div>21</div>
    <div>56</div>
    <div>16</div>
    <div>89</div>
    <div>94</div>
    <div>46</div>
    <div>26</div>
    <div>67</div>
    <div>90</div>
    <div>25</div>
    <div>10</div>
    <div>84</div>
    <div>76</div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script>
    //此处写代码
    $('div').click(function(){
/*$(this).css('text-indent','0px');*/
$(this).css('text-indent','0px').siblings('div').css('text-indent','-9999px');
//指定查找div,所以siblings('div'),不然h1也是兄弟元素,会被弄到影响
});

    </script>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读