比如在表单内填完数字“60”后,点击“提交”然后就返回结果“合格”?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>判断语句</title>
<script type="text/javascript">
function add()
{var score=document.form1.score.value;
if(score>=60)
{
document.write("很棒,成绩及格了。");
}
else
{
document.write("加油,成绩不及格。");
}}
</script>
</head>
<body>
<form name="form1" action="index.html" method="post">
总分:<input type="text" name="score" id="score" value="">
<input type="button" name="sumbit" value="提交" onclick="add()"/>
</form>
</body>
</html>
<!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
{
document.write("要努力了!");
}
}
</script>
</head>
<body>
<input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!" />
</body>
</html>
<script type="text/javascript"> function button(){ var score; if(score>=60{ alert("合格") } else{ alert("不合格") } } </script> <input type="button" name="sumbit" value="提交" onclick="button()"