<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>
HTML上的简单计算器
最新推荐文章于 2022-08-13 17:53:13 发布