请告诉我如何从"这个"获得课程名称?在jquery中的每个循环中。 我需要它,因为我想使用类名在第一个
中选择另一个类名这里是代码。我给了我一个错误
$("#WebPartWPQ3 .ms-itmhover").each(function(){ $(this.attr('class')+" td").css("background","black") });
答案 0 :(得分:0)
您可以改为使用 .find() :
$("#WebPartWPQ3 .ms-itmhover").each(function(){
$(this).find("td").css("background","black")
});
答案 1 :(得分:0)
它应该是:
$(this).attr('class');
但更清洁的方法是:
$(this).find("td").css("background","black");
完整代码:
$("#WebPartWPQ3 .ms-itmhover").each(function(){
$(this).find("td").css("background","black");
});
答案 2 :(得分:0)
您可以尝试this.className
获取课程名称:
$("#WebPartWPQ3 .ms-itmhover").each(function(){
$('.'+this.className+" td").css("background","black");
});
但我建议您进入选择器循环的上下文:
$(this).find("td").css("background","black");
或
$("td", this).css("background","black");
答案 3 :(得分:0)
你有错字
$(this.attr('class')+" td")
// ^ need to close $(this) and than have to use .find()
$("#WebPartWPQ3 .ms-itmhover").each(function(){
$(this).find("td").css("background","black");
});
<小时/> 或
$("#WebPartWPQ3 .ms-itmhover").each(function(){
var cls = $(this).attr('class').split(' ').join('.');
$('.'+ cls +" td").css("background","black")
});