<table id="tblEmployee" class="normal_table">
<tr>
<td>Employee Name</td><td>Department Name</td><td>Salary</td>
</tr>
<tr>
<td>Jane Smith</td><td>Marketing</td><td>$95,000</td>
</tr>
<tr>
<td>John Smith</td><td>Technology</td><td>$90,000</td>
</tr>
<tr>
<td>Brian Adam</td><td>Sales</td><td>$72,000</td>
</tr>
<tr>
<td>Mary Jones</td><td>Support</td><td>$60,000</td>
</tr>
<tr>
<td>Michael Jefferson</td><td>Technology</td><td>$85,000</td>
</tr>
</table>
<br /> <input id="btnTestIt" type="button" value="Test It"> <script type="text/javascript">
$(document).ready(function () {
$("#btnTestIt").click(function () {
var jqObj = $("tr:gt(0)").map(function () {
return $(this).children().first().text();
}) $(jqObj).each(function (index, elem) {
ZEUS.DEBUG.log(elem);
}); ZEUS.DEBUG.log("---------------------------");
var employees = jqObj.get().join(", ");
ZEUS.DEBUG.log(employees);
});
});
</script>

$("tr:gt(0)") selects all the HTML elements with the tag name "tr" except for the first record and returns the
jQuery object.

.map() iterates through each element from the set of selected elements and processes them in the function.
return $(this).children().first().text() returns the text content of the first child element (td) of each
selected "tr" element, which is the employee name.
A new jQuery object (jqObj) is created that contains elements as a result of the return value of the function.

jqObj.get() gets all the HTML elements from the jQuery object as an array.

.join(", ") joins all elements from the array, delimits them with commas (,) and returns a string that contains
a comma-delimited list of all the employees’ names.

jQuery Recipies - 使用map来过滤对应的元素集的更多相关文章

  1. jquery原型方法map的使用和源码分析

    原型方法map跟each类似调用的是同名静态方法,只不过返回来的数据必须经过另一个原型方法pushStack方法处理之后才返回,源码如下: map: function( callback ) { re ...

  2. jQuery选择器的分类之过滤选择器

    jQuery选择器的分类之过滤选择器 上一篇文章为大家简单呢的介绍了jQuery选择器中的基本选择器,层级选择器,表单选择器,接下来就带大家了解一下过滤选择器... 过滤选择器都分为哪些??? 1.基 ...

  3. jQuery的offset、position、scroll,元素尺寸、对象过滤、查找、文档处理

    jQuery_offset和position var offset = $('.xxx').offset() console.log(offset.left.,offset.top)xxx相对于页面左 ...

  4. javascript与jQuery的each,map回调函数参数顺序问题

    <script> var arr = [2,3,6,7,9]; //javascript中的forEach 和 map方法 arr.forEach(function(value,index ...

  5. 用jQuery实现搜索框的过滤效果

    遇到的问题: 1.动态添加了某些元素,在动态添加的某个元素上绑定事件失效 原因:因为需要绑定的元素的直接父元素也是动态添加的解决:向上为上一级父元素绑定事件 $(".check-box&qu ...

  6. 原生JS forEach()和map()遍历,jQuery$.each()和$.map()遍历

    一.原生JS forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...

  7. automapper如何全局配置map条件过滤null值空值对所有映射起效

    原文 automapper如何全局配置map条件过滤null值空值对所有映射起效 我们在使用automapper的时候经常会遇到这样的问题:假设展示给用户的数据我们用UserDto类,User类就是我 ...

  8. js进阶 11-19 jquery如何查找选择器的第一个父亲元素和第一个定位的父元素

    js进阶 11-19 jquery如何查找选择器的第一个父亲元素和第一个定位的父元素 一.总结 一句话总结:closest()方法获得匹配选择器的第一个祖先元素,从当前元素开始沿 DOM 树向上.of ...

  9. (转)Jquery获取上级、下级或者同级的元素

    下面介绍JQUERY的父,子,兄弟节点查找方法 jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$(&qu ...

随机推荐

  1. npoi的用法,动态的判断单元格的大小,设置列的宽度

    public MemoryStream GridToExcelByNPOI(DataTable dt, string strExcelFileName) { HSSFWorkbook wk = new ...

  2. AtCoder - 3939 Strange Nim

    Problem Statement Takahashi and Aoki are playing a stone-taking game. Initially, there are N piles o ...

  3. 【折半枚举】Ural Championship April 30, 2017 Problem G. Glasses with solutions

    题意:有n杯盐溶液,给定每杯里面盐的质量以及盐溶液的质量.问你有多少种方案选择一个子集,使得集合里面的盐溶液倒到一个被子里面以后,浓度为A/B. 折半枚举,暴力搜索分界线一侧的答案数,跨越分界线的答案 ...

  4. 【DFS】【拓扑排序】【动态规划】Gym - 100642A - Babs' Box Boutique

    给你10个箱子,有长宽高,每个箱子你可以决定哪个面朝上摆.把它们摞在一起,边必须平行,上面的不能突出来,问你最多摆几个箱子. 3^10枚举箱子用哪个面.然后按长为第一关键字,宽为第二关键字,从大到小排 ...

  5. 【枚举】【字符串哈希】Gym - 101164K - Cutting

    给你A B两个串,让你切B串两刀,问你能否把切开的三个串拼成A. 哈希显然. #include<cstdio> #include<cstring> using namespac ...

  6. 【二分查找】POJ2456-Aggressive cows

    [题目大意] 有N间牛舍和M头牛,告诉你每个牛舍的位置,求出两头牛之间最小距离的最大值. [思路] 二分判断两头牛之间的最小距离d,通过贪心法进行验证. #include<iostream> ...

  7. Spring beans.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. codevs 1962 马棚问题--序列型DP

    1962 马棚问题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 每天,小明和他的马外出,然后他们一边跑一边玩耍.当他们结束 ...

  9. mysql 下 计算 两点 经纬度 之间的距离 含具体sql语句

    文章转载地址 http://blog.sina.com.cn/s/blog_7bbfd5fd01017d1e.html 感谢作者. 在原文的基础上,我新增了sql语句,方便大家理解 mysql距离计算 ...

  10. 用asyncio的异步网络连接来获取sina、sohu和163的网站首页

    代码如下: import asyncio async def wget(host): print('wget %s...' % host) connect = asyncio.open_connect ...