如何使用类在jquery中生成数组
如何在jquery中使用class.when单击按钮生成数组如何使用类在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
<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());
});