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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。