点击取消时,如何实现再提示输入?
3 回答
先定义一个变量f=1,while循环判断f的值,如果为1则执行if(score!=null){文中判断代码每次判断后f置0} else
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
<script language="javascript">
function rec(){
var score; //score变量,用来存储用户输入的成绩值。
var f=1;
while(f){
score = prompt("请输入您的成绩!") ;
if(score!=null){
if(score>=90)
{
alert("你很棒!");
f=0;
}
else if(score>=75)
{
alert("不错吆!");
f=0;
}
else if(score>=60)
{
alert("要加油!");
f=0;
}
else
{
alert("要努力了!");
f=0;
}
}
else {
alert("请重新输入成绩!谢谢");
}
}
}
</script>
</head>
<body>
<form>
<input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!">
</form>
</body>
</html>
举报