我這樣寫為什么不行
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
? <script type="text/javascript">
? function rec(){
if(prompt("請輸入你的分數(shù):")>=90)
{
? document.write("你很棒!");
}
else if(prompt("請輸入你的分數(shù):")>=75)
? ? {
? document.write("不錯吆!");
}
else if(prompt("請輸入你的分數(shù):")>=60)
? ? {
? document.write("要加油!");
? ? }
? ? else if(prompt("請輸入你的分數(shù):")<60)
{
? ? ? ?document.write("要努力了!");
}
? }
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />
</body>
</html>
2016-10-12
<!DOCTYPE html>
<html>
<head>
? <meta charset="UTF-8">
? <title>prompt</title>
? <script type="text/javascript">
? function rec(){
? ? var score=prompt("請輸入你的成績:");
? ? if (score>=90) {
? ? ? document.write("你很棒!");
? ? }
? ? else if (score>=75) {
? ? ? document.write("不錯吆!");
? ? }
? ? else if (score>=60) {
? ? ? document.write("要加油!");
? ? }
? ? else {
? ? ? document.write("要努力了!");
? ? }
? }
? </script>
</head>
<body>
? ?<input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />
</body>
</html>
這樣試試~
2016-10-19
每次執(zhí)行到prompt函數(shù)都會要你重新輸入文本。if..else條件控制語句失去了意義
2016-10-12
沒有定義變量
?function rec(){
var score; //score變量,用來存儲用戶輸入的成績值。
score =prompt("請輸入你的成績:") ? ? ? ? ? ? ? ?;
if(score>=90)
2016-10-12
不行,沒有定義變量
2016-10-12
else{if.....},少大括號了
2016-10-12
不行,沒有定義變量,要用變量存儲數(shù)據(jù)(每次輸入的分值);否則就像你的代碼沒有存儲數(shù)據(jù),如果每次輸入10分的號,要輸入3遍才能顯示“要努力了!”。