我有一个分页表,里面有一些价格。我想突出显示表中的最低价格。我的价格位于第 6,7 和第 8 列。我需要评估每一行。该脚本做得很好,但不幸的是,当我转到另一个页面时,样式丢失了。我想我必须使用 jQuery on() 方法,但由于我对 javascript 和 jQuery 非常陌生,所以这对我来说是个谜。
到目前为止,我正在使用此代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$('tr').each(function() {
var vals = $('td:nth-child(6),td:nth-child(7),td:nth-child(8)', this).map(function() {
return parseFloat($(this).text(), 10) ? parseFloat($(this).text(), 10) : null;
}).get();
// then find their minimum
var min = Math.min.apply(Math, vals);
// tag any cell matching the min value
$('td:nth-child(6),td:nth-child(7),td:nth-child(8)', this).filter(function() {
return parseFloat($(this).text(), 10) === min;
}).addClass('alert alert-success');
});
</script>