js-计算器
<div class="main"><h1>HTML5-计算器</h1>
<input id="num1" class="num" type="number"/>
<span id="operator">+</span>
<input id="num2" class="num" type="number"/>
<a>=</a>
<input id="num3" class="num" type="number" disabled="disabled"/>
<input id="add" class="operator" type="button" value="+">
<input id="sub" class="operator" type="button" value="-">
<input id="mul" class="operator" type="button" value="*">
<input id="div" class="operator" type="button" value="÷">
<input id="qc" class="operator" type="button" value="清除">
</div>
<script>
var num1=document.getElementById("num1");
var num2=document.getElementById("num2");
var num3=document.getElementById("num3");
var num;
add.onclick=function(){
operator.innerHTML="+";
num3.value=parseInt(num1.value)+parseInt(num2.value);
}
sub.onclick=function(){
operator.innerHTML="-";
num3.value=parseInt(num1.value)-parseInt(num2.value);
}
mul.onclick=function(){
operator.innerHTML="*";
num3.value=parseInt(num1.value)*parseInt(num2.value);
}
div.onclick=function(){
operator.innerHTML="/";
num3.value=parseInt(num1.value)/parseInt(num2.value)
}
qc.onclick=function(){
num1.value='';
num2.value='';
num3.value='';
}
</script>