<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var calc = {
first:0,
second:0,
init:function(){
this.first = parseInt(document.getElementById("first").value);
this.second = parseInt(document.getElementById("second").value);
},
setResult:function(){document.getElementById("result").value = this.result},
add:function(){
this.init();
this.result = this.first + this.second;
this.setResult();
},
minus:function(){
this.init();
this.result = this.first - this.second;
this.setResult();
},
plus:function(){
this.init();
this.result = this.first * this.second;
this.setResult();
},
divide:function(){
this.init();
this.result = this.first / this.second;
this.setResult();
}
};
</script>
<form id="jisuanqi" action="#">
<p>
<label for="first">数字1:</label>
<input id="first" type="text" />
</p>
<p>
<label for="second">数字2:</label>
<input id="second" type="text" />
</p>
<p>
<label for="result">结果:</label>
<input id="result" type="text" />
</p>
<br /><button onclick="calc.add();;return false;" value="加" >加</button>
<button onclick="calc.minus();;return false;" value="减" >减</button>
<button onclick="calc.plus();;return false;" value="乘" >乘</button>
<button onclick="calc.divide();;return false;" value="除" >除</button>
</form>
</body>
</html>
鼠标单击之前
鼠标单击之后