- 我们可以使用onclick 方法 点击 通过 $(’#xx’).css(‘background’,’#f9f9f9’); 设置背景颜色属性。
//html 代码
<div id="exerciseresult" class="col-xl-12 col-lg-12">
<div id="header">
<div id="report" onclick="loadReport()" >评估报告</div>
<div id="answerExplain" onclick="loadAnswerExplain()">答案解析</div>
</div>
</div>
<script type="text/javascript">
function loadReport(){
$('#report').css('background','#04bd97');
$('#report').css('color','white');
$('#answerExplain').css('background','#f9f9f9');
$('#answerExplain').css('color','black');
}
function loadAnswerExplain(){
$('#report').css('background','#f9f9f9');
$('#report').css('color','black');
$('#answerExplain').css('background','#04bd97');
$('#answerExplain').css('color','white');
}
</script>
效果如图: