我正在做一个项目。在我使用ajax更新和计算分数,这是正常的。但是,我有一个根据分数变化的配色方案。颜色确实会发生变化,但仅在页面刷新后才会更改。无论如何,我可以通过刷新页面来改变颜色吗?
以下是我用来分配颜色的代码:
<?php $row_class = "";
while($row = mysql_fetch_assoc($dbResult1))
{
if($row['total_mai'] <= 2)
$row_class = "success";
else if($row['total_mai'] >= 5)
$row_class = "danger";
else if($row['total_mai'] >= 3 and $row['total_mai'] < 5)
$row_class = "warning";
// echo $row_class;
?>
在另一页中,这是一个问题的示例,它有三个答案,根据答案,根据分数分配颜色
<tr>
<td class="form-group col-md-6">Is the duration of therapy acceptable?</td>
<td class="form-group col-md-6">
<p class="radio-inline">
<input type="radio" name="therapydur" id="j1" value="0" <?php echo $j1; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','0','<?php echo $row['p_id']; ?>')">
<a href="#" data-toggle="tooltip" data-placement="top" title="acceptable">A</a>
</input></p>
<p class="radio-inline">
<input type="radio" name="therapydur" id="j2" value="0" <?php echo $j2; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','0','<?php echo $row['p_id']; ?>')">
<a href="#" data-toggle="tooltip" data-placement="top" title="marginally acceptable">B</a>
</input></p>
<p class="radio-inline">
<input type="radio" name="therapydur" id="j3" value="1" <?php echo $j3; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','1','<?php echo $row['p_id']; ?>')">
<a href="#" data-toggle="tooltip" data-placement="top" title="unacceptable">C</a>
</input></p>
</td>
</tr>
Here is the ajax from the same page:
<script language="javascript" type="text/javascript">
function ajaxFunction(title,id,val,p_id)
{
//alert("test");
//alert(id);
//alert(val);
//alert(title);
//alert(p_id);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert(xmlhttp.responseText);
var resp = xmlhttp.responseText;
var split_v = resp.split("__");
//alert(split_v.length);
//alert(split_v[1]);
document.getElementById("ajaxDiv_"+id).innerHTML=split_v[0];
document.getElementById("ajaxTotal").innerHTML=split_v[1];
}
}
xmlhttp.open("GET","ajax_mai.php?pdr_id="+id+"&value="+val+"&title="+title+"&p_id="+p_id,true);
xmlhttp.send();
return true;
}
</script>