輸入結果不對,求解答
function rec(){
var score; //score變量,用來存儲用戶輸入的成績值。
score = prompt("輸入你的成績");
? ? if(score=null){
? ? ? ? document.write("OK");
? ? }
if(score>=90)
{
? document.write("你很棒!");
}
else if(score>=75)
? ? {
? document.write("不錯吆!");
}
else if(score>=60)
? ? {
? document.write("要加油!");
? ? }
? ? else
{
? ? ? ?document.write(score+"要努力了!");
}
? 這時候我沒有輸入,點擊取消 -----> 結果是 null 要努力了。
但是如果去掉?
if(score=null){
? ? ? ? document.write("OK");
? ? }
這一句,顯示就是要努力了,為什么 null 不見了。
2016-04-21
if(score=null){//這里判斷條件錯了,應該是scroe==null;
? ? ? ? document.write("OK");
?}
score=null;是給score賦了一個null的值,無論輸入是什么,代碼執行到上面的語句后,都把score的值重新賦值為null了,所以? 都會執行 document.write(score+"要努力了!")
2016-04-17
同學,最后的if語句中的判斷條件要用score==null ?你那是賦值,判斷結果永遠都是true
2016-04-17
=是賦值,表示等于要用==