Javascript 如何检索属性数据id值​;不点击

Javascript 如何检索属性数据id值​;不点击,javascript,jquery,codeigniter,Javascript,Jquery,Codeigniter,如何检索所有数据id属性值?我尝试过使用jquery,但只获得了1个id或1个值 我的代码 <div class="col text-right mr-1"> <a href="" class="show_more comment-count-custom" id="show_more" data-idpost="<?= $p["id_post"] ?>">show more comments</a> </div> 我得到

如何检索所有数据id属性值?我尝试过使用jquery,但只获得了1个id或1个值

我的代码

 <div class="col text-right mr-1">
    <a href="" class="show_more comment-count-custom" id="show_more" data-idpost="<?= $p["id_post"] ?>">show more comments</a>
 </div>
我得到的结果

从所有
中构建
数据idpost
值的数组。显示可以使用
map()
的更多
元素:

var idData=$('.show_more').map((i,el)=>el.dataset.idpost.get();
console.log(idData)

如果
将\u more
类显示为多个。您可以使用with和
jquery.get()
api方法

varids=$(“.show_more”).map((i,elem)=>$(elem.data(“idpost”).get()
console.log(ids)

这种行为不应该令人惊讶!“返回匹配元素集中第一个元素在命名数据存储中的值”
var id = $(".show_more").data("idpost");
console.log(id)