1
我想改变使用Backbone和jQuery的两个元素子元素的CSS。我的代码不起作用。我认为问题在于DOM元素和jQuery对象之间存在差异。无法更改jquery对象css
这里是我的代码:
App.Views.ExploreCard.user = App.Views.ExploreCard.Parent.extend({
name: 'user',
allowUntyped: true,
classes: 'explore-person-box shadowed',
onclick: function() {
window.location.assign(this.data.profilePath);
},
postRender: function() {
App.HCS.redrawHCS(this.$el);
}
});
和
App.HCS = {
redrawHCS: function(elements) {
elements.each(function(index, value) {
console.log(value);
var hcs = $(value).find('.score');
var border = $(value).find('.user-card-avatar-round');
var score = $(hcs).html();
console.log(hcs);
console.log(border);
console.log(score);
if (score <= 33 && score >= 1) {
$(hcs).css("background-image", "image-url('heart_primary.png')");
$(border).css("border", "3px solid #ff4013;");
}
else if (score <= 66 && score >= 34) {
$(hcs).css("background-image", "image-url('body_primary.png')");
$(border).css("border", "3px solid #008cb4;");
}
else if (score <= 99 && score >= 67) {
$(hcs).css("background-image", "image-url('minf_primary.png')");
$(border).css("border", "3px solid #fb9f00;");
}
});
}
};
我不想做任何事情非常困难。只需改变一些CSS规则。
我错过了什么?
是你的'.score'和'。用户卡,化身round'的div,输入还是什么? –
'if'显示之前那三个'console.log()'语句是什么? (另外,不是问题,但你可以说'hcs.css(...)'和'border.css(...)' - 不需要将变量包装在'$()'中,因为'hcs'和'border'已经是jQuery对象。) – nnnnnn
'score'似乎是一个字符串,但是你将它与数字进行比较。也许你应该明确地转换它? – propeller