Jquery 如果值小于或等于,则查找文本并添加类
如果类的值小于或等于Jquery 如果值小于或等于,则查找文本并添加类,jquery,Jquery,如果类的值小于或等于40%,我想将其添加到表中的 我很确定这可以通过jQuery实现。但我做不到 我已经试过了 方法#1 var $rows = $('#report-card table tr'); $rows.each(function(i, item) { $this = $(item); if ($this.text()) <= '40 %' ) { $this.addClass('fail'); } }); var$rows=$(“#报
40%,我想将其添加到表中的
我很确定这可以通过jQuery实现。但我做不到
我已经试过了
方法#1
var $rows = $('#report-card table tr');
$rows.each(function(i, item) {
$this = $(item);
if ($this.text()) <= '40 %' ) {
$this.addClass('fail');
}
});
var$rows=$(“#报告卡表tr”);
$rows.每个(功能(i,项){
$this=$(项目);
如果($this.text())看着你的小提琴,你应该这样做
$(document).ready(function() {
$('#report-card table tr').each(function(){
if ($.trim($(this).find('td:last').text()) <= '40 %') {
$(this).addClass("fail");
}
});
});
$(文档).ready(函数(){
$(“#成绩单表tr”)。每个(函数(){
如果($.trim($(this).find('td:last').text())请尝试以下操作:
$('#report-card table tr:gt(0)').each(function () {
var txt = $(this).find("td:last").text();
txt = txt.substr(0, txt.length - 2);
txt = parseInt(txt);
if (txt <= 40) {
$(this).addClass("fail");
}
});
$(“#报告卡表tr:gt(0)”。每个(函数(){
var txt=$(this.find(“td:last”).text();
txt=txt.substr(0,txt.length-2);
txt=parseInt(txt);
如果(txt您可以更改:
$this = $(item); //<----------wrong selector
if ($this.text()) <= '40 %' ) { //<-------here extra ')' after .text()
$this.addClass('fail');
}
$this=$(item);//谢谢Ramesh,我试过这个代码,但对我不起作用。谢谢Jai指出我的错误,你可以看到我是个新手:)所以非常感谢你的帮助哦,太好了!这对你有帮助了。
$this = $(item); //<----------wrong selector
if ($this.text()) <= '40 %' ) { //<-------here extra ')' after .text()
$this.addClass('fail');
}
$this = $(item).find('td:last');
if ($this.text() <= '40 %' ) {
$this.closest('tr').find('td').addClass('fail'); // <---update to this
}