我有这个 HTML
<td colspan="4" class="item"> DERBY LINE, VT 05830<br>
<label for="" data-sort="16.26">UPS Ground $16.26</label><br>
<label for="" data-sort="27.57">UPS 3 Day Select® $27.57</label><br>
<label for="" data-sort="33.87">UPS 2nd Day Air® $33.87</label><br>
<label for="" data-sort="72.82">UPS Next Day Air $72.82</label><br>
<label for="" data-sort="7.99">USPS Priority $7.99</label><br>
<label for="" data-sort="9.61">FEDEX SmartPost® FedEx Delivered Via USPS $9.61</label><br>
<input type="button" name="Button5" id="Button5" onmouseout="this.className='btn'" onmouseover="this.className='btn_over'" onclick="document.shipquote.action='shipquote.asp?action=clean';document.shipquote.submit();" value="Clear" class="btn">
</td>
我需要它通过“数据排序”属性对其进行排序,现在我正在使用 这个元素排序器 但是当我运行脚本时它返回这个
<td colspan="4" class="item"> DERBY LINE, VT 05830<br>
<label for="" data-sort="16.26">UPS Ground $16.26</label><br>
<label for="" data-sort="27.57">UPS 3 Day Select® $27.57</label><br>
<label for="" data-sort="33.87">UPS 2nd Day Air® $33.87</label><br>
<label for="" data-sort="7.99">USPS Priority $7.99</label><br>
<label for="" data-sort="72.82">UPS Next Day Air $72.82</label><br>
<label for="" data-sort="9.61">FEDEX SmartPost® FedEx Delivered Via USPS $9.61</label><br>
<input type="button" name="Button5" id="Button5" onmouseout="this.className='btn'" onmouseover="this.className='btn_over'" onclick="document.shipquote.action='shipquote.asp?action=clean';document.shipquote.submit();" value="Clear" class="btn">
</td>
如您所见,它运行但由于某种原因它只获得 attr 上的第一个数字。我正在使用的电话如下:
$('.item label').sortElements(function(a, b){
return $(a).attr("data-sort") > $(b).attr("data-sort") ? 1 : -1;
});
我究竟做错了什么?