我在我的頁面上有這樣的內容。用Jquery閱讀風格屬性
<div class="number_1" style="background-color:red"></div>
<div class="number_2" style="background-color:yellow"></div>
<div class="number_3"></div>
<div class="number_4"></div>
<div class="number_5" style="background-color:red"></div>
我不能通過添加background-color類來更改HTML代碼!它必須從風格變成紅色!
我需要這樣的
for(var i=1; i<=5; i++){
if($('.number_'+i).hasBackgroundColor('red')){
//something
}else{
//somethign else
}
}
.attr('style')==='background-color: red'
功能不似乎工作
.css('background-color')
也不要似乎工作
你是如何使用的CSS()
$('<div style="background-color:red"></div>').attr('style') === 'background-color: red'
假
$('<div style="background-color:red"></div>').attr('style') === 'background-color:red'
真:步伐將給出不同的結果? –
JQuery具有.css()。看看他們的文檔在這裏:http://api.jquery.com/css/。他們也有很好的演示。 –
實際上,attr('style')工作,只是IE從其他瀏覽器返回不同的字符串。 – sinisake