• jquery 中 eq()遍历方法 和:eq()选择器的区别


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    *{margin: 0;padding: 0;list-style: none;}
    .box{ 100px;height: 404px;border:1px solid red;margin: 0 auto;}
    li{ 100px;height: 100px;font-size: 40px;line-height: 100px;color: #ccc;text-align: center;border-bottom: 1px solid red;}
    </style>
    <script src="js/jquery-1.11.1.min.js"></script>
    <script>
    $(function(){
    // eq()方法的定义和用法:
    // 此方法能够获取匹配元素集上的相应位置索引的元素。
    // 匹配元素集上元素的位置索引是从0开始的。
    //
    // :eq()选择器的定义和用法:
    // 此选择器匹配一个给定索引值的元素。
    // 元素的位置索引从0算起。
    //
    // 可以直接使用.eq(index),
    // 若要使用eq选择器则要写成:eq(‘+index+’)这样获取到的index才是变量

    var index=0;
    $("li:eq(index)").css("background","red")// 错误


    $("li:eq("+index+")").css("background","blue") //正确
    $("li").eq(index+1).css("background","blue")//正确
    })
    </script>
    </head>
    <body>
    <div class="box">
    <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    </ul>
    </div>
    </body>
    </html>

  • 相关阅读:
    CF1270H. Number of Components
    NOI Online Round2划水记
    uoj#247. 【Rujia Liu's Present 7】Mysterious Space Station口胡
    mysql习题
    MySQL基础
    python网络编程(进程与多线程)
    xshell连接虚拟机Ubuntu问题
    python来写打飞机
    timeit模块
    python常用模块
  • 原文地址:https://www.cnblogs.com/wyan20/p/5676040.html
Copyright © 2020-2023  润新知