https://ithelp.ithome.com.tw/questions/10205651
關於這篇文章,請問只執行一次藍紅就停止,該修改哪裡達到無限循環?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>測試</title>
<script>
setInterval(function(){blink.color='#0000ff'?'red':'blue'},300)
</script>
</head>
<body>
<blink>
<font face="標楷體" color="blue" id="blink" style="font-size:36pt">
測試
</font>
</blink>
</body>
</html>
樓下 Homura
的方法比較好~我多宣告了一個變數,感覺繞了一下路,已修正
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>測試</title>
<script>
setInterval(function(){blink.color=blink.color==="blue"?"red":"blue"},300)
</script>
</head>
<body>
<blink>
<font face="標楷體" color="blue" id="blink" style="font-size:36pt">
測試
</font>
</blink>
</body>
</html>
setInterval(function(){blink.color='#0000ff'?'red':'blue'},300
你的if else判別式明顯有問題....
if條件只有'#0000ff'
'#0000ff'因為是靜態的結果永遠都是true
只會一直進入if條件
怎麼樣都跑不到else條件
改成跟自己color比較這樣就OK了
setInterval(function(){blink.color=blink.color==='blue'?'red':'blue'},300)