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