码迷,mamicode.com
首页 > Web开发 > 详细

js实现两个文本框数值的加减乘除运算

时间:2017-10-03 21:37:32      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:nbsp   tle   function   head   func   utf-8   char   fun   rip   

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function count(){
var a = parseInt(document.getElementById("tex1").value);
var b = parseInt(document.getElementById("tex2").value);
var selectSign = document.getElementById("select").value;

switch (selectSign)
{
case ‘+‘: answer = a+b;break;
case ‘-‘: answer = a-b;break;
case ‘*‘: answer = a*b;break;
case ‘/‘: answer = a/b;
}
document.getElementById("fruit").value = answer;
}
</script>
</head>
<body>
<input type="text" id="tex1" />
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="tex2" />
<input type="button" value=" = " onclick="count()" />
<input type="text" id="fruit" onclick="count()" />
</body>
</html>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function count(){
var a = parseInt(document.getElementById("tex1").value);
var b = parseInt(document.getElementById("tex2").value);
var selectSign = document.getElementById("select").value;

switch (selectSign)
{
case ‘+‘: answer = a+b;break;
case ‘-‘: answer = a-b;break;
case ‘*‘: answer = a*b;break;
case ‘/‘: answer = a/b;
}
document.getElementById("fruit").value = answer;
}
</script>
</head>
<body>
<input type="text" id="tex1" />
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="tex2" />
<input type="button" value=" = " onclick="count()" />
<input type="text" id="fruit" onclick="count()" />
</body>
</html>

 

js实现两个文本框数值的加减乘除运算

标签:nbsp   tle   function   head   func   utf-8   char   fun   rip   

原文地址:http://www.cnblogs.com/apolloren/p/7624516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!