亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

prompt 消息對話框 不輸入、亂輸入,怎樣提示并恢復對話?

<!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變量,用來存儲用戶輸入的成績值。
?? ?score = prompt("輸入你的成績:");?????????????? ;
?? ?if(score>=90)
?? ?{
?? ??? document.write("你很棒!");
?? ?}
?? ?else if(score>=75)
??? {
?? ??? document.write("不錯吆!");
?? ?}
?? ?else if(score>=60)
??? {
?? ??? document.write("要加油!");
??? }

?? else if(score= )? {}?? //我不輸入任何值or我亂輸入,怎樣提示用戶不要亂玩,并恢復對話?
??? else
?? ?{
?????? document.write("要努力了!");
?? ?}
? }
? </script>
</head>
<body>
??? <input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />
</body>
</html>

正在回答

3 回答

<!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變量,用來存儲用戶輸入的成績值。

score = ?prompt("請輸入你的成績"); ? ? ? ? ? ? ?;

if(score>=90&&score<100)

{

? document.write("你很棒!");

}

else if(score>=75&&score<90)

? ? {

? document.write("不錯吆!");

}

else if(score>=60&&score<75)

? ? {

? document.write("要加油!");

? ? }

? ? else if(score<60&&score>=0){

? ? ? ?document.write("要努力了!");

}

? ? else{

? ? ? ? document.write("你輸入的數字無效請刷新重試!");

? ? }

? }

? </script>

</head>

<body>

? ? <input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />

</body>

</html>

//這樣可以嗎?

1 回復 有任何疑惑可以回復我~
#1

雷叔愛吃各種面 提問者

非常感謝!
2016-11-22 回復 有任何疑惑可以回復我~

<!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 zhengcflag,score; //score變量,用來存儲用戶輸入的成績值。

? ? do

? ? { ??

? ? ? ? zhengcflag=true;

? ? ? ? score = prompt("輸入你的成績:"); ? ? ? ? ? ? ? ;

? ? ? ? if(score>=90)

? ? ? ? {

? ? ? ? ? ? document.write("你很棒!");

? ? ? ? }

? ? ? ? else if(score>=75)

? ? ? ? {

? ? ? ? document.write("不錯吆!");

? ? ? ? }

? ? ? ? else if(score>=60)

? ? ? ? {

? ? ? ? ? ?document.write("要加油!");

? ? ? ? }

? ? ? ? else if(0<=score&&score<60)

? ? ? ? {

? ? ? ? ? ? document.write("要努力了!");

? ? ? ? }

? ? ? ? else?

? ? ? ? {

? ? ? ? ? ?zhengcflag=false;

? ? ? ? ? ?document.write("重新輸入!");

? ? ? ? }

? ? }

? ? while(zhengcflag==false)

? }

? </script>

</head>

<body>

? ? <input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />

</body>

</html>

設個標志判斷是否正常輸入,剛剛寫的時候0<=score&&score<60忘了寫&&,把我瀏覽器弄崩潰了,無語

0 回復 有任何疑惑可以回復我~
#1

雷叔愛吃各種面 提問者

lol,謝謝
2016-11-22 回復 有任何疑惑可以回復我~

var reg = new RegExp("^\\d+$");

if (!reg.test(score)) {

alert("請輸入數字");

rec();

return;

}

if (score.length >= 3) {

alert("請輸入正確數字");

rec();

return;

}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

prompt 消息對話框 不輸入、亂輸入,怎樣提示并恢復對話?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號