JS 写两数相加正数页面变红负数页面变绿

来源:百度知道 编辑:UC知道 时间:2024/05/27 00:06:10
怎么在JS理判断颜色 输出

输入a<input type="text" name="a"><br>
输入b<input type="text" name="b"><br>
<input type="button" onclick="chgColor()" value="计算"><br>
<script>
function chgColor()
{
var a=parseInt(document.getElementById("a").value);
var b=parseInt(document.getElementById("b").value);
if(a+b>0)
document.body.bgColor="red";
else
document.body.bgColor="green";
}
</script>