我想通过jQuery更改div的CSS。以下是jQuery代码。从jQuery更改CSS
$(".endPollingButton").click(function() {
var endPollingCode = $(this).attr("value");
var correctAnswer = parseInt($(this).attr("id"));
for(LCV=1;LCV<=5;LCV++) {
if(LCV == correctAnswer) {
$("#"+endPollingCode).children(".Bars_"+LCV).css("background-color","green");
alert("check");
} else {
$("#"+endPollingCode).children(".Bars_"+LCV).css("background-color","red");
alert("check");
}
}
});
下面是HTML代码:
for($LCV = 1; $LCV <= $rowCount; $LCV++) {
echo "<div class='graphBlock' id='".$questionCode[$LCV]."' value=''>";
echo "<div id='questionCodeBar'>Quiz Code: ".$questionCode[$LCV]."</div>";
echo "<div id='questionTitleBar'>".$questionName[$LCV]."</div>";
echo "<span class='barsInfo' id='barsInfo1".$LCV."'></span><div class='bars_1' id='bars1".$LCV."' style='width:;'></div>";
echo "<span class='barsInfo' id='barsInfo2".$LCV."'></span><div class='bars_2' id='bars2".$LCV."' style='width:;'></div>";
echo "<span class='barsInfo' id='barsInfo3".$LCV."'></span><div class='bars_3' id='bars3".$LCV."' style='width:;'></div>";
echo "<span class='barsInfo' id='barsInfo4".$LCV."'></span><div class='bars_4' id='bars4".$LCV."' style='width:;'></div>";
echo "<span class='barsInfo' id='barsInfo5".$LCV."'></span><div class='bars_5' id='bars5".$LCV."' style='width:;'></div>";
echo "<button class='endPollingButton' id='".$correctAnswer[$LCV]."' value='".$questionCode[$LCV]."' >End Polling</button>";
echo "</div>";
}
上面的代码无法正常工作。我不确定是否有任何语法错误。两个检查警报正在工作。如果您需要更多代码,例如与之相关的HTML代码,请告诉我,我很乐意提供。如果可以的话请帮忙。谢谢。
Pleaseee help .......
在第二个CSS调用''background-color“。”red“中有一个点,你的if语句应该用比较运算符'=='测试,而不是赋值运算符'=' – Stphane 2013-02-25 16:05:07
你有没有检查了Firebug中的错误控制台? – HerrSerker 2013-02-25 16:07:33
民意调查真的有一个正确的答案? :) – Andbdrew 2013-02-25 16:10:43