我想在 jQuery 中使用单一方法来设置文本颜色和文本本身,如假设/失败的方法所示:
$("#north_america_stat").css({
color : northAmericaColour,
text: northAmerica
});
“文本:northAmerica”不起作用。
我知道可以像这样单独设置它们:
$("#north_america_stat").text(northAmerica);
然后:
$("#north_america_stat").css({
color : northAmericaColour,
});
但为了使代码更紧凑,我想将这些方法合并为一个 - 这可能吗?
最佳答案
一种方法是链接
它们。
$('#north_america_stat')
.css({color: northAmericaColour})
.text(northAmerica);
另一种方法是使用 CSS content
属性。
$("#north_america_stat").css({
color : northAmericaColour,
"content": northAmerica
});
关于jquery - 在 jQuery 中结合 .text() 和 .css() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22518643/