Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery can';t获取每个具有数据属性的div的数据id_Jquery_Html - Fatal编程技术网

Jquery can';t获取每个具有数据属性的div的数据id

Jquery can';t获取每个具有数据属性的div的数据id,jquery,html,Jquery,Html,我试图获取特定div中每个div的数据id中的每个id。因此,我得到[7,7,7],但我只有3个具有不同数据id的div 这是我的html: <div id="activated_blocs"> <div class="bloc-row" data-id="7"> <div class="bloc-row" data-id="9"> <div class="bloc-row" data-id="8"> </div> 如何使

我试图获取特定div中每个div的数据id中的每个id。因此,我得到[7,7,7],但我只有3个具有不同数据id的div

这是我的html:

<div id="activated_blocs">
  <div class="bloc-row" data-id="7">
  <div class="bloc-row" data-id="9">
  <div class="bloc-row" data-id="8">
</div>

如何使用[7,9,8]获取我的数组?

因为在循环中,您需要使用当前元素,
good\u order
是一个jQuery对象,它引用多个元素,调用
。数据('id')
将始终返回该集合中第一个元素的
数据id

var good_order=$(“#已激活的_blocs”).find(“.bloc行”);
var test_array=good_order.map(函数(){
返回$(this.data('id'))
}).get();
log(JSON.stringify(test_数组))

你说得对,我完全忘记了$(这个)。谢谢
var good_order = $('#activated_blocs').find('.bloc-row');
    var test_array = [];
    $.each(good_order, function() {
        test_array.push(good_order.data('id'));
    });
    console.log(test_array);