大家好我有像
这样的字段 <div class="dlt_distance_slab">
<div class="dl_distance_slab">
<label for="upto"><g:message code="rule.upto.label" default="Upto" /></label>
</div>
<div class="dt_distance_slab_show">
<g:formatNumber number="${ruleInstance?.distanceSlabLimit1}" type="number" maxFractionDigits="2" class="distanceSlablimit" /> Km
</div>
</div>
<div class="dlt_distance_slab">
<div class="dl_distance_slab">
<label for="upto"><g:message code="rule.upto.label" default="Upto" /></label>
</div>
<div class="dt_distance_slab_show">
<g:formatNumber number="${ruleInstance?.distanceSlabLimit2}" type="number" maxFractionDigits="2" class="distanceSlablimit" /> Km
</div>
</div>
<div class="dlt_distance_slab">
<div class="dl_distance_slab">
<label for="upto"><g:message code="rule.upto.label" default="Upto" /></label>
</div>
<div class="dt_distance_slab_show">
<g:formatNumber number="${ruleInstance?.distanceSlabLimit3}" type="number" maxFractionDigits="2" class="distanceSlablimit" /> Km
</div>
</div>
我想选择值为&gt;的最后一个formatNumber字段0(所有formatNumber Fiels都有相同的class =“distanceSlablimit”
如何使用jquery
答案 0 :(得分:1)
首先,您可以过滤所选元素using a function as a parameter for .filter()
。然后,您只需使用.last()
。
parseInt()
用于将值转换为数字。确保始终指定第二个参数(基数),否则您会注意到一些"strange" behaviour。例如,'010'
将被转换为数字8
,因为在Javascript中,起始零表示八进制数。
$('.distanceSlablimit').filter(function () {
//replace val() with text() if the elements are not form elements
return parseInt($(this).val(), 10) > 0;
}).last();
答案 1 :(得分:-1)