作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我到处都在做这种事情,我正在寻找最有效的(计算上和句法上)执行方式:
ids =[]
$('tr.selectON td').each( function() {
var answer_query = $(this).attr('id');
if ( answer_query !== undefined ) {
ids.push( answer_query )
}
});
我可以访问 underscore.js,我想这会有所帮助。
最佳答案
ids = $("tr.selectON td[id]").map(function() { return this.id; }).get();
文档:
获取具有id
属性的元素 http://api.jquery.com/attribute-contains-prefix-selector/
过滤id属性 http://api.jquery.com/map/
将结果转换成数组 http://api.jquery.com/get/
关于javascript - JQuery 选择器重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13276836/
我是一名优秀的程序员,十分优秀!