gpt4 book ai didi

javascript - JQuery 选择器重写

转载 作者:行者123 更新时间:2023-11-30 07:09:46 25 4
gpt4 key购买 nike

我到处都在做这种事情,我正在寻找最有效的(计算上和句法上)执行方式:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com