Blogger Information
Blog 20
fans 0
comment 0
visits 25111
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用JavaScript做闰年与成绩判断2
左手Leon的博客
Original
827 people have browsed it

实例-javascript闰年判断与成绩判断

<!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中使用“.”。如果连接符少了,不会提示错误,但也不显示信息


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!