為什么我這樣不能實(shí)現(xiàn)什么都不填,不顯示"要努力了“,而顯示:"請(qǐng)輸入你的成績"

半ping鹽汽水
2014-08-25
3 回答
舉報(bào)
0/150
提交
取消
2014-08-31
你的代碼測(cè)試,什么都不輸入。
1。點(diǎn)擊確定,prompt函數(shù)會(huì)返回""空字符串,會(huì)將空字符串作為你的函數(shù)返回值,這個(gè)值不符合你的任何一個(gè)判斷標(biāo)準(zhǔn),就會(huì)出現(xiàn)“要努力了”。
2。點(diǎn)擊取消,prompt函數(shù)會(huì)返回null這個(gè)值,于是就會(huì)出現(xiàn)“請(qǐng)輸入你的成績”。
兩種點(diǎn)擊會(huì)得到兩種不同結(jié)果。
2014-08-25
我剛才試了一下你的代碼是顯示要努力了,而不是請(qǐng)輸入你的成績啊
2014-08-25
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
<script language="javascript">
function rec(){
var score; //score變量,用來存儲(chǔ)用戶輸入的成績值。
score = prompt("請(qǐng)輸入你的考試成績:") ;
if(score!=null){
if(score>=90)
{
document.write("你很棒!");
}
else if(score>=75)
{
document.write("不錯(cuò)吆!");
}
else if(score>=60)
{
document.write("要加油!");
}
else if(score>=0)
{
document.write("要努力了!");
}
}
else{
document.write("請(qǐng)輸入你的成績");
}
}
</script>
</head>
<body>
<form>
<input name="button" type="button" onClick="rec()" value="點(diǎn)擊我,對(duì)成績做評(píng)價(jià)!">
</form>
</body>
</html>