按下取消之后怎樣才能不顯示要努力了
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
? <script type="text/javascript">
? function rec(){
var score; //score變量,用來(lái)存儲(chǔ)用戶輸入的成績(jī)值。
score = prompt()? ? ? ? ? ? ? ?;
if(score>=90)
{
? ?document.write("你很棒!");
}
else if(score>=75)
? ? {
? ?document.write("不錯(cuò)吆!");
}
else if(score>=60)
? ? {
? ?document.write("要加油!");
? ? }
? ? else(score<60)
{
? ? ? ?document.write("要努力了!");
? ? else(score!=0&&score=null)
}
? }
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="rec()" value="點(diǎn)擊我,對(duì)成績(jī)做評(píng)價(jià)!" />
</body>
</html>
2019-03-29
if(score>=90)
{
? ?document.write("你很棒!");
}
else if(score>=75)
? ? {
? ?document.write("不錯(cuò)吆!");
}
else if(score>=60)
? ? {
? ?document.write("要加油!");
? ? }
? ? else if(score>0)
{
? ? ? ?document.write("要努力了!");
}
改成這樣就好了,當(dāng)前面的if語(yǔ)句和else if語(yǔ)句都沒(méi)執(zhí)行的時(shí)候就會(huì)默認(rèn)執(zhí)行else,你點(diǎn)取消返回一個(gè)null值,前面的都不符合,所以他會(huì)默認(rèn)執(zhí)行最后一個(gè),輸出一個(gè)要努力了,你把else刪了,改成else if,當(dāng)他不合符條件的時(shí)候就不會(huì)有默認(rèn)操作