我试图从具有特定类的表格单元格中获得最高数字(下面的示例中为8).我假设我必须将它转换为数组,然后对它进行math.max吗?
这是我的HTML代码:
<table>
<tr>
<td class="id">3</td>
</tr>
<tr>
<td class="id">8</td>
</tr>
<tr>
<td class="id">4</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的,但它只返回384.所以math.max不适用于它.
var varID = $('.id').text();
var varArray= jQuery.makeArray(varID);
alert (varArray);
Run Code Online (Sandbox Code Playgroud)
Und*_*ned 12
我认为最好的方法是:
var max = 0;
$('.id').each(function()
{
$this = parseInt( $(this).text() );
if ($this > max) max = $this;
});
alert(max);
Run Code Online (Sandbox Code Playgroud)
试试这个:
var high = Math.max.apply(Math, $('.id').map(function(){
return $(this).text()
}))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7783 次 |
| 最近记录: |