prompt中,如果要判斷是否輸入怎么辦?以下是代碼
如果不輸入內(nèi)容,prompt接收的值并不是null。
<html>
<head>
<title>無標(biāo)題文檔</title>
<script type="text/javascript">
function rec(){
var score=prompt("請輸入你的分?jǐn)?shù)");
if(score!=null){
if(score>=98)
document.write("你很棒!");
else if(score>=75)
document.write("不錯");
else if(score>=60)
document.write("要jiayou");
else
document.write("要努力");
}
else
alert("輸入內(nèi)容為空?。?!");//判斷無效
}
</script>
</head>
<body>
<input name="button" type="button"onClick="rec()"
value="點擊我,對成績做評價" />
</body>
</html>
2016-12-19
?我是這么寫的
function rec(){
var score; //score變量,用來存儲用戶輸入的成績值。
score =prompt("請輸入你的成績:"); ? ? ? ? ? ? ? ?;
if(!score)
? ? {
? ? ? ?document.write("請輸入內(nèi)容")
}
? ? else if(score>=90)
{
? document.write("你很棒!");
}
else if(score>=75)
? ? {
? document.write("不錯吆!");
}
else if(score>=60)
? ? {
? document.write("要加油!");
? ? }
? ? else
{
? ? ? ?document.write("要努力了!");
}
? }
2016-12-19
<html>
<head>
<title>無標(biāo)題文檔</title>
<script type="text/javascript">
function rec(){
????var score=prompt("請輸入你的分?jǐn)?shù)");
????if(score!=null){
????????if(score>=98)
????????????document.write("你很棒!");
????????else if(score>=75)
????????????document.write("不錯");
????????else if(score>=60)
????????????document.write("要jiayou");
????????else
????????????document.write("要努力");
????}
????else
????????var tem=confirm("你還沒有輸入成績!");
????????alert(tem);
}
</script>
</head>
<body>
<input name="button" type="button"onClick="rec()"
value="點擊我,對成績做評價" />
</body>
</html>