我想要獲得連續的所有td
的寬度的數組。首先,我得到的所有td
的陣列:jquery:獲得連續寬度的td的數組
datas = $('.totals').prev().find("tr").last().find("td");
然後測試,我正確使用$.map
方法,我有它輸出的每個元素:
$.map(datas, function(the_data){console.log(the_data)});
上面的代碼返回:
<td class="col col-name">18</td>
<td class="col col-1">1</td>
<td class="col col-2">2</td>
<td class="col col-3">0</td>
<td class="col col-4">3</td>
<td class="col col-5">3%</td>
我現在嘗試運行$.map
方法,收集所有的td
的寬度:
$.map(datas, function(the_data){the_data.width();});
上述返回的代碼:
VM4255:1 Uncaught TypeError: the_data.width is not a function
at <anonymous>:1:42
at Function.map (jquery.self-bd7ddd3….js?body=1:485)
at <anonymous>:1:3
我也曾嘗試:
$.map(datas, function(){$(this).width();});
但只是返回一個空數組。
如何獲得寬度數組?
你的map函數中的對象'the_data'不是一個jQuery對象,你試過這個$(the_data)嗎? –
@ÁngelB。這工作!如果你把它作爲答案,我會標記它正確 – Philip7899