各位大神幫下忙吧,我想問下:點擊取消按鈕怎么回到點擊按鈕界面,我點擊取消他顯示的也是"要努力了",我空值點擊確定他也顯示的是“要努力了”,要怎么才能空值情況下提示“請輸入分數(shù)”
?<script type="text/javascript">
? function rec(){
?? ?var score; //score變量,用來存儲用戶輸入的成績值。
?? ?score =prompt("請輸入你的分數(shù)")?????????????? ;
?? ?if(score>=90)
?? ?{
?? ??? document.write("你很棒!");
?? ?}
?? ?else if(score>=75)
??? {
?? ??? document.write("不錯吆!");
?? ?}
?? ?else if(score>=60)
??? {
?? ??? document.write("要加油!");
??? }
??? else
?? ?{
?????? document.write("要努力了!");
?? ?}
? }
? </script>
2019-03-17
<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>=0&&score!=null)
{
? ? ? ?document.write("要努力了!");
}
else if(score==null)
{
? ? ? ?document.write(value);
}
? }
? </script>
這樣點取消就回到按鈕"點擊我,對成績做評價!"
2019-03-16
2019-02-08
?function rec(){
var score; //score變量,用來存儲用戶輸入的成績值。
score = prompt("你的分數(shù):") ;
? ? if(score==null||score=="")return false; //對返回null和空值的情況作出判斷
if(score>=90)
{
? ? ? ? document.write("非常棒!");
}
else if(score>=75)
? ? {
? ?document.write("不錯吆!");
}
else if(score>=60)
? ? {
? ?document.write("要加油!");
? ? }
else if(score>=0)
{
? ?document.write("要努力了!");
}
? ? else{
? ? ? ? document.write("輸入的格式有誤!");
? ? }
? }
2018-11-13
搞定沒 我這個可以幫你搞定
<!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 =='' || score == null)
?? ?{
?? ??? alert('請輸入分數(shù)!');
?? ?}
?? ?else if(score <60)
?? ?{
?????? document.write("要努力了!");
?? ?}
? }
? </script>
</head>
<body>
??? <input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />
</body>
</html>
2018-11-08
<!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("你考了多少分","60") ? ? ? ? ? ? ? ;
if(score>=90)
{
? document.write("你很棒!");
}
else if(score>=75)
? ? {
? document.write("不錯吆!");
}
else if(score>=60)
? ? {
? document.write("要加油!");
? ? }
else if(score==null){
? ?alert("別點取消!")
}
else if(score==""){
? ?alert("別空著,請輸入分數(shù)!")
}
? ? else
{
? ? ? ?document.write("要努力了!");
}
? }
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="rec()" value="點擊我,對成績做評價!" />
</body>
</html>
2018-09-30
很簡單,如果你沒有輸入按確認,他就會返回一個空字符串"",而不是null,這里注意一下就行了
2018-09-29
這里好像是固定的 你可以用記事本試試 按照你的想法 要定義兩個函數(shù)方法 一個是讓用戶輸入成績的,另一個是判斷分數(shù)的 在這里 如果輸入的分數(shù)==null 就調(diào)用第一個函數(shù)方法.....
2018-09-28
<!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==null){
? ? ? ?document.write("請輸出分數(shù)!");? ??
? ? }
? ? else 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>
弄好了,這里 if score=null ,應(yīng)該寫成if score==null就好了。
2018-09-28
<!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=null){
? ? ? ?document.write("請輸出分數(shù)!");? ??
? ? }
? ? else 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>
我是這樣寫的,但也是不行,有沒有前輩幫幫忙!
或者是讓繼續(xù)跳出alert,警告請輸入分數(shù)!
多謝!
2018-09-25
語法:
參數(shù)說明: