Blogger Information
Blog 9
fans 0
comment 1
visits 4240
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
3月29日作业
红叶的博客
Original
474 people have browsed it

代码:

实例

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
	<title>3.迷你计算器</title>
</head>
<body>

	<input type="text" name="one" id="one" placeholder="第一个数字">
	<select name="js" id="js">
		<option value="kong">符号</option>
		<option value="jia">+</option>
		<option value="jian">-</option>
		<option value="cheng">*</option>
		<option value="chu">/</option>
	</select>
	<input type="text" name="two" id="two" placeholder="第二个数字">
	<input type="submit" name="submit" id="submit" value="计算" onclick="jisuan();">

	<p>结果:<span id="jg"></span></p>

	<script type="text/javascript">
		function jisuan(){
			var one = document.getElementById('one')
			var two = document.getElementById('two')
			var js = document.getElementById('js')
			var jg = document.getElementById('jg')

			if(one.value.length == 0){
				jg.innerHTML = '请输入第一个数字'
				return false
			}else if(isNaN(one.value)){
				jg.innerHTML = '非法数字'
				return false
			}else if(two.value.length == 0){
				jg.innerHTML = '请输入第二个数字'
				return false
			}else if(isNaN(two.value)){
				jg.innerHTML = '非法数字'
				return false
			}else{
				var one = parseFloat(one.value)
				var two = parseFloat(two.value)
			}

			switch(js.value){
				case 'kong':
					jg.innerHTML = '请选择操作类型'
					break
				case 'jia':
					jg.innerHTML = one + two
					break
				case 'jian':
					jg.innerHTML = one - two
					break
				case 'cheng':
					jg.innerHTML = one * two
					break
				case 'chu':
					if(two==0){
						jg.innerHTML = '除数不能为零'
						return false
					}
					jg.innerHTML = one / two
					break
			}
		}
	</script>

</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

手写代码:

1.jpg2.jpg

Correction status:qualified

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