if選擇問題
<!DOCTYPE html>
<html>
<body>
<input type="button"
onclick="f1()"
value="改變背景色">
<p id="p2">嘖嘖嘖</p>
<script>
function f1()
{
if (document.body.style.backgroundColor="lavender")
{
document.body.style.backgroundColor="grey"; //為什么背景顏色只和這行代碼有關(guān)?
}
else
{
document.body.style.backgroundColor="lavender";
}
}
</script>
</body>
</html>
2020-04-08
<body>
<input type="button"
onclick="f1()"
value="改變背景色">
<p id="p2">嘖嘖嘖</p>
<script>
function f1()
{
if (document.body.style.backgroundColor="lavender") //if內(nèi)為“==”
{
document.body.style.backgroundColor="grey"; //if條件成立時(shí),執(zhí)行此段代碼
}
/*else這塊黑體代碼可去掉*/
else
{
document.body.style.backgroundColor="lavender";
}
}
</script>
</body>
2021-02-22
== = === 三者的區(qū)別