<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
var Txt1=document.getElementById("txt1").value;
var Txt2=document.getElementById("txt2").value;
var SEL=document.getElementById("select").value;
var result="";
switch(SEL){
case "+":
result=parseInt(Txt1) + parseInt(Txt2);
break;
case "-":
result=parseInt(Txt1) - parseInt(Txt2);
break;
case "*":
result=parseInt(Txt1) * parseInt(Txt2);
break;
default:
result=parseInt(Txt1) / parseInt(Txt2);
}
document.getElementById("fruit").value=result;
//获取第一个输入框的值
//获取第二个输入框的值
//获取选择框的值
//获取通过下拉框来选择的值来改变加减乘除的运算法则
//设置结果输入框的值
}
</script>
</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='fruit' />
</body>
</html>JavaScript实现的网页计算器功能
简易计算器实现
最新推荐文章于 2024-07-02 15:31:55 发布
本文介绍了一个简单的网页版计算器实现方法,该计算器使用HTML进行界面布局,通过JavaScript实现基本的算术运算功能,包括加、减、乘、除等操作。
5306

被折叠的 条评论
为什么被折叠?



