jQuery Recipies - 使用map来过滤对应的元素集
<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来过滤对应的元素集的更多相关文章
- jquery原型方法map的使用和源码分析
原型方法map跟each类似调用的是同名静态方法,只不过返回来的数据必须经过另一个原型方法pushStack方法处理之后才返回,源码如下: map: function( callback ) { re ...
- jQuery选择器的分类之过滤选择器
jQuery选择器的分类之过滤选择器 上一篇文章为大家简单呢的介绍了jQuery选择器中的基本选择器,层级选择器,表单选择器,接下来就带大家了解一下过滤选择器... 过滤选择器都分为哪些??? 1.基 ...
- jQuery的offset、position、scroll,元素尺寸、对象过滤、查找、文档处理
jQuery_offset和position var offset = $('.xxx').offset() console.log(offset.left.,offset.top)xxx相对于页面左 ...
- javascript与jQuery的each,map回调函数参数顺序问题
<script> var arr = [2,3,6,7,9]; //javascript中的forEach 和 map方法 arr.forEach(function(value,index ...
- 用jQuery实现搜索框的过滤效果
遇到的问题: 1.动态添加了某些元素,在动态添加的某个元素上绑定事件失效 原因:因为需要绑定的元素的直接父元素也是动态添加的解决:向上为上一级父元素绑定事件 $(".check-box&qu ...
- 原生JS forEach()和map()遍历,jQuery$.each()和$.map()遍历
一.原生JS forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...
- automapper如何全局配置map条件过滤null值空值对所有映射起效
原文 automapper如何全局配置map条件过滤null值空值对所有映射起效 我们在使用automapper的时候经常会遇到这样的问题:假设展示给用户的数据我们用UserDto类,User类就是我 ...
- js进阶 11-19 jquery如何查找选择器的第一个父亲元素和第一个定位的父元素
js进阶 11-19 jquery如何查找选择器的第一个父亲元素和第一个定位的父元素 一.总结 一句话总结:closest()方法获得匹配选择器的第一个祖先元素,从当前元素开始沿 DOM 树向上.of ...
- (转)Jquery获取上级、下级或者同级的元素
下面介绍JQUERY的父,子,兄弟节点查找方法 jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$(&qu ...
随机推荐
- BootstrapTable与KnockoutJS相结合实现增删改查功能
http://www.jb51.net/article/83910.htm KnockoutJS是一个JavaScript实现的MVVM框架.通过本文给大家介绍BootstrapTable与Knock ...
- HDU 6464.免费送气球-动态开点-权值线段树(序列中第first小至第second小的数值之和)(感觉就是只有一个状态的主席树) (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)
免费送气球 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- SyntaxError: Non-ASCII character '\xe7' in file 9.py on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
解决方法: #!/usr/bin/python #-*-coding:utf-8-*-
- 524. Longest Word in Dictionary through Deleting【Medium】【删除后得到的字典中的最长单词】
Given a string and a string dictionary, find the longest string in the dictionary that can be formed ...
- 04、Unity 5--全局光照技术
本文整理自Unity全球官方网站,原文:UNITY 5 - LIGHTING AND RENDERING 简介全局光照,简称GI,是一个用来模拟光的互动和反弹等复杂行为的算法,要精确的仿真全局光照非常 ...
- 【树形dp】Godfather
[POJ3107]Godfather Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7212 Accepted: 253 ...
- [CODE FESTIVAL 2017]Poor Penguin
题意:在一个$n\times m$的网格上,每个格子是薄冰或冰山(网格外什么都没有),有一片薄冰上站着一只企鹅,对于薄冰$(i,j)$,如果不满足($(i-1,j),(i+1,j)$都有东西或$(i, ...
- 【Matrix-tree定理】【BEST Theorem】hdu6064 RXD and numbers
题意:给你一张有向图,求从1出发,回到1的欧拉回路数量. 先特判掉欧拉回路不存在时的情况. 看这个吧:http://blog.csdn.net/yuanjunlai141/article/detail ...
- 【预处理】Codeforces Round #407 (Div. 2) C. Functions again
考虑枚举每个子串开头的位置,然后答案转化成询问这个位置之后 哪个位置的前缀和 - 这位置的前缀和 最大(当然是已经把绝对值和正负的情况处理好了,可以发现按奇偶,这个序列只有两种情况),只需要预处理这两 ...
- 1.创建spring cloud父工程和子模块
创建父工程 idea创建父工程 idea创建一个工程.父工程管理公共资源 添加子模块 选择添加到父工程里面spring_cloud_parent 相应的子模块添加到父工程的pom.xml文件里