HTML上的简单计算器

来源:互联网 发布:虚拟软件 编辑:程序博客网 时间:2024/05/17 08:41

<html>
<head>
<title>简易计算器</title>
</head>
<body>
<center>
<h2>简易计算器</h2><br/>
第一个数<input type="text" id="one">
<br/>第二个数<input type="text" id="two">
<br/><input type="button" value="  +  " onclick="add()">
<input type="button" value="  -  " onclick="jian()">
<input type="button" value="  x  " onclick="cheng()">
<input type="button" value="  ÷  " onclick="chu()">
<br/>计算结果<input type="text" id="result">
</center>
<script>
var one=document.getElementById("one");
var two=document.getElementById("two");
var result=document.getElementById("result");
function add(){
 result.value=parseFloat(one.value)+parseFloat(two.value); 
}
function jian(){ 
 result.value=parseFloat(one.value)-parseFloat(two.value);
}
function cheng(){ 
 result.value=parseFloat(one.value)*parseFloat(two.value);
}
function chu(){ 
 result.value=parseFloat(one.value)/parseFloat(two.value);
}
</script>
</body>
</html>

0 0
原创粉丝点击