JavaScript進階篇 1-2編程練習
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全帶,準備啟航</title>
<!--引入外部文件的方式-->
<script type="text/javascript" >
//多行注釋
?
//在頁面中顯示文字
document.write("系好安全帶,準備起航--目標JS")
function zhangwo () {
var aa=confirm("準備好了嗎?");
?? if (aa=true)
{ document.write("準備好了,起航吧!");}
?? else
{ document.write("去學習JS入門篇");}
}
//頁面中彈出提示框
//單行注釋
?
</script>
</head>
<body>
<input name="buttom" type="button" onclick="zhangwo()"value="點擊我,彈出對話框"/>
</body>
</html>
為什么我點擊取消還是會顯示“準備好了,起航吧!"?
2016-05-10
是aa==true
2016-05-10
= 是賦值 == 是判斷是否相等
aa=true 要換成a==true
2016-05-10
==是判斷符號 ?=是賦值符合
2016-05-10
aa=true是賦值,應該用aa==true來判斷是否相等。
2016-05-10
aa=confirm("準備好了嗎?");這個你可以理解為賦值
aa==confirm("準備好了嗎?");這個才是用來判斷相等的!
2016-05-10
? if (aa=true)
這里少了個等號,改成? if (aa==true) 就好了