JS和HTML5结合做一个简单的网页计算器
2017-03-28 10:34
573 查看
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gbk"/>
<title>简单计算器</title>
</head>
<body>
<input type="text" id="txt1"/>
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="txt2"/>
<input type="button" value="=" onclick="count()"/>
<input type="text" id="result"/>
<script type="text/javascript">
function count()
{
var txt1=parseInt(document.getElementById("txt1").value);
var txt2=parseInt(document.getElementById("txt2").value);
var select=document.getElementById("select").value;
var result="";
switch(select)
{
case "+":result=txt1+txt2;break;
case "-":result=txt1-txt2;break;
case "*":reault=txt1*txt2;break;
case "/":reault=txt1/txt2;break;
}
document.getElementById("result").value=result;
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gbk"/>
<title>简单计算器</title>
</head>
<body>
<input type="text" id="txt1"/>
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="txt2"/>
<input type="button" value="=" onclick="count()"/>
<input type="text" id="result"/>
<script type="text/javascript">
function count()
{
var txt1=parseInt(document.getElementById("txt1").value);
var txt2=parseInt(document.getElementById("txt2").value);
var select=document.getElementById("select").value;
var result="";
switch(select)
{
case "+":result=txt1+txt2;break;
case "-":result=txt1-txt2;break;
case "*":reault=txt1*txt2;break;
case "/":reault=txt1/txt2;break;
}
document.getElementById("result").value=result;
}
</script>
</body>
</html>
相关文章推荐
- JS实现一个简单的网页钟表
- 使用JSP制作一个超简单的网页计算器的实例分享
- 使用JSP制作一个超简单的网页计算器的实例分享
- 一个基于JavaScript的简单网页计算器
- js网页版计算器的简单实现
- js网页版计算器的简单实现
- 黑马程序员-HTML和CSS结合做的一个计算器的简单页面
- 利用htm+css+js编写一个网页计算器
- 用JS 写个非常简单的计算器 算是学习JS的一个开头
- 使用node.js ,Express, 和Mongodb 简历一个简单的Restful 网页服务-part1
- js网页版计算器的简单实现
- J2EE实践第一部分-创建一个简单的JSF Web程序(简单网页计算器)
- 用JS+Html5实现一个简单的音乐播放器
- 网页计算器 一个JS计算器
- 如何使用JS编写一个简单的计算器
- 用JS实现了一个简单的计算器。
- Html+JS创建一个简单的计算器
- 用最简单快捷的方法用js写一个计算器
- JS实现一个简单的计算器
- 网页基础第4课之“简单的JS与CSS结合--鼠标移入移出事件”