`

七、has|each|map

 
阅读更多

/*
 * 通过map可以有效的将某个包装集中的元素转换为数组
 */
var ps = $("tbody td:nth-child(1)").map(function(){
    var n = $(this).next("td");
    var p = {"id":$(this).html(),"name":n.html()};
    return p;
}).get();

for(var i=0;i<ps.length;i++) {
    alert(ps[i].name);
}

 

$(function() {
    //获取存在有ul的li,返回的是新包装集
    $("li").has("ul").css("color","#f00");
   
    $("div").has("span").css("color","#f00");
});

 

$(function() {
    var ns = $("tbody td:nth-child(2)");
    /**
     * 使用以下方法进行遍历基本上是基于js进行操作
     * 对于jquery有自己的一套遍历方法,可以直接通过
     * each函数进行遍历
     */
    /*for(var i=0;i<ns.length;i++) {
        var nn = ns[i];//nn已经是js的节点
        var id = $(ns[i]).prev("td").html();
        var age = $(ns[i]).next("td").html();
        nn.innerHTML = id+">>"+nn.innerHTML+"("+age+")";
    }*/
   
    /**
     * 对于JQuery而言,可以用each遍历所有的数组对象
     * each中的匿名函数n表示的是数组的下标,从0开始
     */
    ns.each(function(n){
        $(this).html($(this).prev("td").html()+
            "."+$(this).html()+
            "("+$(this).next("td").html()+")");   
    });
});

分享到:
评论

相关推荐

    MMATrans.rar_Grid map_The First_z map_z-map

    Each row has a constant Y coordinate. Grid row 1 corresponds to ylo and the last grid row corresponds to yhi. Within each row, the Z values are arranged from xlo to xhi. The following example grid ...

    JS实现的自定义map方法示例

    接着,我们展示了如何使用`size`,`get`,`remove`方法以及`eachMap`方法来操作这个自定义`Map`。 `eachMap`方法的使用,通过`console.log`打印出所有的键和值,这展示了自定义`Map`的遍历功能。在实际开发中,你...

    浅析jQuery 遍历函数,javascript中的each遍历_.docx

    15. `.map()` 方法:把当前匹配集合中的每个元素传递给函数,产生包含返回值的新 jQuery 对象。 16. `.next()` 方法:获得匹配元素集合中每个元素紧邻的同辈元素。 17. `.nextAll()` 方法:获得匹配元素集合中每个...

    编译原理龙书答案

    and we can find a simple way to map roman to arabic numerals. For example: XII =&gt; X, II =&gt; 10 + 2 =&gt; 12 CXCIX =&gt; C, XC, IX =&gt; 100 + 90 + 9 =&gt; 199 MDCCCLXXX =&gt; M, DCCC, LXXX =&gt; 1000 + 800 + 80 =&gt; 1880 ...

    Hive on Spark EXPLAIN statement

    Hive on Spark EXPLAIN statement : 讲述了 Common Join / Map join / Bucket Map Join / Sorted Merge Bucket Map Join / skew join 在explain 中的 树结构 。In Hive, command EXPLAIN can be used to show the ...

    JQuery新版中文手册

    each(callback) size() length selector context get([index]) index([selector|element]) 数据缓存 data([key],[value]) removeData([name|list])1.7* $.data(element,[key],[value]) 队列控制 queue...

    map:您一直想要的ruby容器:有序的字符串符号无关紧要的哈希

    4. **遍历操作**:可以使用`each`、`each_key`、`each_value`或`each_pair`方法遍历`Map`中的所有元素。由于有序性,遍历会按照插入的顺序进行。 5. **删除操作**:`delete`方法允许删除指定键的键值对,如`map....

    一个简单的JavaScript Map实例(分享)

    在JavaScript ES6及更高版本中,通常建议使用原生的Map对象,因为它提供了更全面的功能,如迭代器支持,以及`set`, `has`, `clear`等方法,这些方法在自定义Map实现中没有。原生Map也具有性能优势,因为它们是原生...

    Semi-Automatic 2D-to-3D Conversion Using disparity propagation

    Then, the initial disparity map is assigned to each key frame with the aid of various preset disparity models for each object. After the disparity assignment step, disparity maps for other frames of ...

    Laravel开发-eloquent-only

    9. **集合(Collections)**: Eloquent查询返回的是一个集合对象,类似于PHP的数组,但具有丰富的实用方法,如`each`、`map`、`pluck`、`where`等。 10. **分页(Pagination)**: Eloquent提供了便捷的分页功能,`...

    浅析jQuery 遍历函数,javascript中的each遍历

    - .map():把当前匹配集合中的每个元素传递给函数,产生包含返回值的新***y对象。 - .next():获得匹配元素集合中每个元素紧邻的下一个同辈元素。 - .nextAll():获得匹配元素集合中每个元素之后的所有同辈元素。 - ...

    jquery1.11.0手册

    map(callback) has(expr|ele) not(expr|ele|fn) slice(start,[end]) 查找 children([expr]) closest(e|o|e)1.7* find(e|o|e) next([expr]) nextall([expr]) nextUntil([e|e][,f]) offsetParent() ...

    2016美赛数学建模特等奖论文

    Then we used data from 83 countries to verify our model, and found a similar water scarcity distribution compared to UN’s “World Scarcity Map”. By providing sensitivity analysis on  ,we ...

    Learning iOS Game Programming

    Each chapter describes in detail a specific component within the game,along with the technology required to support it,be it a tile map editor,or some effect we’re trying to create with OpenGL ES....

    Markov Chain Monte Carlo in Practice

    Each of these studies applied Markov chain Monte Carlo methods to produce more accurate and inclusive results. General state-space Markov chain theory has seen several developments that have made it ...

    Faster R-CNN

    scores at each position. RPNs are trained end-to-end to generate highquality region proposals, which are used by Fast R-CNN for detection. With a simple alternating optimization, RPN and Fast R-CNN ...

    Kidnapped vehicle_python_sensor_estimate_AStepataTime_detection_

    Luckily it has a map of this location a (noisy) GPS estimate of its initial location and lots of (noisy) sensor and control data.In this project you will implement a 2 dimensional particle filter in ...

    ExcelUtils-2.00.zip

    4、#each ${model} ${width1},${width2},model can be a Map,JavaBean,Collection or Array object, #each key will show all property of the model.${width?} means merge ${width?} cells. If only one ...

    Keyframe-based monocular SLAM: design, survey, and future directions

    Extensive research in the field of monocular SLAM for the past fifteen years has yielded workable systems that found their way into various applications in robotics and augmented reality. Although ...

Global site tag (gtag.js) - Google Analytics