Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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中生成数组_Jquery_Arrays - Fatal编程技术网

如何使用类在jquery中生成数组

如何使用类在jquery中生成数组,jquery,arrays,Jquery,Arrays,如何在jquery中使用class.when单击按钮生成数组 <table id="tblResult"> <tr class="tblRows"> <td class="clsPhone">Sony</td> </tr> <tr class="tblRows"> <td class="clsPhone">Samsung</td> </tr> <tr class="t

如何在jquery中使用class.when单击按钮生成数组

<table id="tblResult">
<tr class="tblRows">
    <td class="clsPhone">Sony</td>
</tr>
<tr class="tblRows">
    <td class="clsPhone">Samsung</td>
</tr>
<tr class="tblRows">
    <td class="clsPhone">LG</td>
</tr>
var arr=$(“#tblResult tr td”).map(函数(){
返回$(this.text())
}).get();
控制台日志(arr)

索尼
三星
LG

像这样的东西应该可以做到

 var arr = [];
    $('.tblRows').each(function(){
        arr.push($(this).find('.clsPhone').text)
    });
这应该行得通

var arr = new Array();

$('#tblResult').find('.clsPhone').each(function(){
    arr.push($(this).text());
});
var myArray=[];
$('.clsPhone')。每个(函数(){
myArray.push($(this.html());
});
log(myArray)

索尼
三星
LG
使用纯javascript

var t=Array.from(document.getElementsByClassName(“clsPhone”)).map(e=>e.innerHTML);
console.log(t)

索尼
三星
LG
var arr = new Array();

$('#tblResult').find('.clsPhone').each(function(){
    arr.push($(this).text());
});