怎么实现当一个字段变为true时,某个页面的背景色变为灰色,
ajax请求判断
<!DOCTYPE html>
<html>
<head>
<center>
<p>change color when true</p>
</center>
<script type="text/javascript">
function change()
{
if(document.getElementById("view").innerHTML == "true")
{
document.getElementById("view").innerHTML = "false";
document.getElementById("color").style.background = "#ff00ff";
}
else
{
document.getElementById("view").innerHTML = "true";
document.getElementById("color").style.background = "#00ff00";
}
}
</script>
</head>
<body>
<center>
<div id="color" style="width:450px; height:380px; background:#ff00ff;">
<button id ="view">false</button>
<br>
<button id="action" onclick="change()" >click the button to change status</button>
</div>
</center>
</body>
</html>