批改状态:未批改
老师批语:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>javascript闰年判断与成绩判断</title>
<script type="text/javascript">
function checkYear(){
var year=document.getElementById("year").value;
if (year%4==0) {
if (year%100==0) {
alert(year+'是世纪闰年');
}else{
alert(year+'是普通闰年');
}
}else{
alert(year+'不是闰年');
};
}
function checkScore(){
var score=document.getElementById("score").value;
if (score>60) {
if (score<=80) {
alert('成绩是'+score+',不错');
}else if(score>80&&score<=100){
alert('成绩是'+score+',非常优秀啊');
}
}else{
alert('成绩是'+score+',还要再努力哦');
};
}
</script>
</head>
<body>
<div name="myDiv">
<input id="year" type="number" placeholder="输入检查的年份">
</div>
<div>
<input id="score" type="number" placeholder="输入检查的成绩">
</div>
<button onclick="checkYear()">闰年判断</button>
<button onclick="checkScore()">成绩判断</button>
</body>
</html>点击 "运行实例" 按钮查看在线实例
学习心得:
1、查找了javascript对input标签中值的提取,有两种方法
一种为document.getElementsById().value
另一种在网页中需要再加一个form,然后使用例如myForm.name.valuer的方法取得值
2、在使用alert输出信息时,字符串与变量的连接需要使用“+”,在php中使用“.”。如果连接符少了,不会提示错误,但也不显示信息
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号