<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. Python3 文件读写r,w,a

    # Author;Tsukasa ''' f = open('yesterday','w') #文件句柄...注意open分为‘r’读模式,‘w’写模式(d会先创建文件或者覆盖文件),‘a’为追加模式 ...

  2. python实现RabbitMQ同步跟异步消费模型

    1,消息推送类 import pika # 同步消息推送类 class RabbitPublisher(object): # 传入RabbitMQ的ip,用户名,密码,实例化一个管道 def __in ...

  3. 洛谷——P2813 母舰

    P2813 母舰 题目背景 广东汕头聿怀初中 Train#3 Problem 1 (有没有红警既视感~) 题目描述 在小A的星际大战游戏中,一艘强力的母舰往往决定了一场战争的胜负.一艘母舰的攻击力是普 ...

  4. luogu P3375 【模板】KMP字符串匹配

    题目描述 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来还要输出子串的前缀数组next.如果你不知道这是什么意思也不要问,去百度搜[ ...

  5. FZU 2105 Digits Count(按位维护线段树)

    [题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and ...

  6. [xsy2282]cake

    题意:一个$n\times n$的有标号点阵,现在用一条直线把它们分成两部分,问有多少种不同的分法 结论:方案数就是以点阵上的点为端点且不经过第三个点的线段数 对一个满足要求的线段,将其绕中点顺时针转 ...

  7. 【动态规划】CDOJ1651 Uestc的命运之旅

    要处理从四个角出发的答案.最后枚举那个交点,然后讨论一下来的方向即可. #include<cstdio> #include<algorithm> using namespace ...

  8. 【期望DP+高斯消元】BZOJ3270-博物馆

    [题目大意] 有m条走廊连接的n间房间,并且满足可以从任何一间房间到任何一间别的房间.两个男孩现在分别处在a,b两个房间,每一分钟有Pi 的概率在这分钟内不去其他地方(即呆在房间不动),有1-Pi 的 ...

  9. android 关于Make sure the plugin is properly configured问题的解决办法

    这个问题引发的原因最初的报错是: [2013-10-14 10:01:58 - XXX] The connection to adb is down, and a severe error has o ...

  10. ncnn阅读 - CMakeLists.txt

    CMAKE_TOOLCHAIN_FILE This variable is specified on the command line when cross-compiling with CMake. ...