<html>
<head>
<title>JiSuanQi</title>
<script>
var oper = ""
var num = 0;
//输入数字
function addNum(n){
var nowNum = myform.num.value;
if(nowNum == "0"){
myform.num.value = n
}else{
myform.num.value = myform.num.value + n;
}
}
//添加运算符
function setOper(op){
oper = op;
num = myform.num.value*1;
}
function getCount(){
if(oper != ""){
if(oper == "+"){
}else if(oper == "-"){
}else if(oper == "*"){
}else if(oper == "/"){
}else if(oper == "%"){
}
}
}
</script>
<style>
#ceng{width:600px;height:650px;background:#323850;}
.jr{background-Image:url('jr.png')}
.mr{background-Image:url('mr.png')}
.ax{background-Image:url('ax.png')}
.fk{background-Image:url('fk.png')}
</style>
</head>
<body bgcolor="green">
<center>
<form id="myform">
<div id="ceng" align="center"><br><br><font size="7">简易计算器</font><br><br>
<table border="1" width="560px" height="480px" align="center">
<tr>
<td colspan="4">
<input id="num" type="text" onfocus="blur()" value="0"/>
</td>
</tr>
<tr>
<td>
<input id="bt1" type="button" value="1" onclick="addNum(1)"/>
</td>
<td>
<input id="bt2" type="button" value="2" onclick="addNum(2)"/>
</td>
<td>
<input id="bt3" type="button" value="3" onclick="addNum(3)"/>
</td>
<td>
<input id="bt10" type="button" value="+" onclick="setOper('+')"/>
</td>
</tr>
<tr>
<td>
<input id="bt4" type="button" value="4" onclick="addNum(4)"/>
</td>
<td>
<input id="bt5" type="button" value="5" onclick="addNum(5)"/>
</td>
<td>
<input id="bt6" type="button" value="6" onclick="addNum(6)"/>
</td>
<td>
<input id="bt11" type="button" value="-" onclick="addNum()"/>
</td>
</tr>
<tr>
<td>
<input id="bt7" type="button" value="7" onclick="addNum(7)"/>
</td>
<td>
<input id="bt8" type="button" value="8" onclick="addNum(8)"/>
</td>
<td>
<input id="bt9" type="button" value="9" onclick="addNum(9)"/>
</td>
<td>
<input id="bt12" type="button" value="*" onclick="addNum()"/>
</td>
</tr>
<tr>
<td>
<input id="bt0" type="button" value="0" onclick="addNum(0)"/>
</td>
<td>
<input id="bt13" type="button" value="." onclick="addNum()"/>
</td>
<td>
<input id="bt14" type="button" value="%" onclick="addNum(1)"/>
</td>
<td>
<input id="bt15" type="button" value="/" onclick="addNum()"/>
</td>
</tr>
<tr>
<td>
<input id="bt16" type="button" value="C" onclick="addNum()"/>
</td>
<td>
<input id="bt17" type="button" value="←" onclick="addNum()"/>
</td>
<td colspan="2">
<input id="bt18" type="button" value="=" onclick="addNum()"/>
</td>
</tr>
</table>
</div>
</form>
</center>
</body>
<script>
for (var i = 0;i<19 ;i++ )
{
document.getElementById("bt"+i).style.width="140px";
document.getElementById("bt"+i).style.height="90px";
document.getElementById("bt"+i).style.fontSize="80px"
document.getElementById("bt"+i).className= "mr"//默认状态按键颜色
document.getElementById("bt"+i).onmouseover = function(){this.className= "jr"};//匿名函数(鼠标进入事件)
document.getElementById("bt"+i).onmouseout = function(){this.className= "mr"};//鼠标移出事件(默认事件)
document.getElementById("bt"+i).onmousedown = function(){this.className= "ax"};//鼠标按下事件
document.getElementById("bt"+i).onmouseup = function(){this.className= "fk"};//鼠标放开事件
}
document.getElementById("bt18").style.width="286px";
document.getElementById("num").style.width="580px";
document.getElementById("num").style.height="90px";
document.getElementById("num").style.fontSize="70px";
</script>
</html>
求 计算器 可以进行连续的加减乘除 这样的代码如何添加 还有如何限制按键数字个数
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- dongjinwang 2015-08-06 02:51关注
JiSuanQi
<br> var oper = ""<br> var num = 0;<br> //输入数字<br> function addNum(n){<br> var nowNum = myform.num.value;<br> if(nowNum == "0"){<br> myform.num.value = n<br> }else{<br> myform.num.value = myform.num.value + n;<br> }<br><br> }<br> //添加运算符<br> function setOper(op){<br> oper = op;<br> num = myform.num.value*1;<br> }<br> function getCount(){<br> if(oper != ""){<br> if(oper == "+"){</p> <pre><code> }else if(oper == "-"){ }else if(oper == "*"){ }else if(oper == "/"){ }else if(oper == "%"){ } } } </script> <style> #ceng{width:600px;height:650px;background:#323850;} .jr{background-Image:url('jr.png')} .mr{background-Image:url('mr.png')} .ax{background-Image:url('ax.png')} .fk{background-Image:url('fk.png')} </style> </head> <body bgcolor="green"> <center> <form id="myform"> <div id="ceng" align="center"><br><br><font size="7">简易计算器</font><br><br> <table border="1" width="560px" height="480px" align="center"> <tr> <td colspan="4"> <input id="num" type="text" onfocus="blur()" value="0"/> </td> </tr> <tr> <td> <input id="bt1" type="button" value="1" onclick="addNum(1)"/> </td> <td> <input id="bt2" type="button" value="2" onclick="addNum(2)"/> </td> <td> <input id="bt3" type="button" value="3" onclick="addNum(3)"/> </td> <td> <input id="bt10" type="button" value="+" onclick="setOper('+')"/> </td> </tr> <tr> <td> <input id="bt4" type="button" value="4" onclick="addNum(4)"/> </td> <td> <input id="bt5" type="button" value="5" onclick="addNum(5)"/> </td> <td> <input id="bt6" type="button" value="6" onclick="addNum(6)"/> </td> <td> <input id="bt11" type="button" value="-" onclick="addNum()"/> </td> </tr> <tr> <td> <input id="bt7" type="button" value="7" onclick="addNum(7)"/> </td> <td> <input id="bt8" type="button" value="8" onclick="addNum(8)"/> </td> <td> <input id="bt9" type="button" value="9" onclick="addNum(9)"/> </td> <td> <input id="bt12" type="button" value="*" onclick="addNum()"/> </td> </tr> <tr> <td> <input id="bt0" type="button" value="0" onclick="addNum(0)"/> </td> <td> <input id="bt13" type="button" value="." onclick="addNum()"/> </td> <td> <input id="bt14" type="button" value="%" onclick="addNum(1)"/> </td> <td> <input id="bt15" type="button" value="/" onclick="addNum()"/> </td> </tr> <tr> <td> <input id="bt16" type="button" value="C" onclick="addNum()"/> </td> <td> <input id="bt17" type="button" value="←" onclick="addNum()"/> </td> <td colspan="2"> <input id="bt18" type="button" value="=" onclick="addNum()"/> </td> </tr> </table> </div> </form> </center> </body> <script> for (var i = 0;i<19 ;i++ ) { document.getElementById("bt"+i).style.width="140px"; document.getElementById("bt"+i).style.height="90px"; document.getElementById("bt"+i).style.fontSize="80px" document.getElementById("bt"+i).className= "mr"//默认状态按键颜色 document.getElementById("bt"+i).onmouseover = function(){this.className= "jr"};//匿名函数(鼠标进入事件) document.getElementById("bt"+i).onmouseout = function(){this.className= "mr"};//鼠标移出事件(默认事件) document.getElementById("bt"+i).onmousedown = function(){this.className= "ax"};//鼠标按下事件 document.getElementById("bt"+i).onmouseup = function(){this.className= "fk"};//鼠标放开事件 } document.getElementById("bt18").style.width="286px"; document.getElementById("num").style.width="580px"; document.getElementById("num").style.height="90px"; document.getElementById("num").style.fontSize="70px"; </script> </code></pre> <p></html></p> <pre><code> <html> <head> <title>JiSuanQi</title> <script> var oper = "" var num = 0; //输入数字 function addNum(n){ var nowNum = myform.num.value; if(nowNum == "0"){ myform.num.value = n }else{ myform.num.value = myform.num.value + n; } } //添加运算符 function setOper(op){ oper = op; num = myform.num.value*1; } function getCount(){ if(oper != ""){ if(oper == "+"){ }else if(oper == "-"){ }else if(oper == "*"){ }else if(oper == "/"){ }else if(oper == "%"){ } } } </script> <style> #ceng{width:600px;height:650px;background:#323850;} .jr{background-Image:url('jr.png')} .mr{background-Image:url('mr.png')} .ax{background-Image:url('ax.png')} .fk{background-Image:url('fk.png')} </style> </head> <body bgcolor="green"> <center> <form id="myform"> <div id="ceng" align="center"><br><br><font size="7">简易计算器</font><br><br> <table border="1" width="560px" height="480px" align="center"> <tr> <td colspan="4"> <input id="num" type="text" onfocus="blur()" value="0"/> </td> </tr> <tr> <td> <input id="bt1" type="button" value="1" onclick="addNum(1)"/> </td> <td> <input id="bt2" type="button" value="2" onclick="addNum(2)"/> </td> <td> <input id="bt3" type="button" value="3" onclick="addNum(3)"/> </td> <td> <input id="bt10" type="button" value="+" onclick="setOper('+')"/> </td> </tr> <tr> <td> <input id="bt4" type="button" value="4" onclick="addNum(4)"/> </td> <td> <input id="bt5" type="button" value="5" onclick="addNum(5)"/> </td> <td> <input id="bt6" type="button" value="6" onclick="addNum(6)"/> </td> <td> <input id="bt11" type="button" value="-" onclick="addNum()"/> </td> </tr> <tr> <td> <input id="bt7" type="button" value="7" onclick="addNum(7)"/> </td> <td> <input id="bt8" type="button" value="8" onclick="addNum(8)"/> </td> <td> <input id="bt9" type="button" value="9" onclick="addNum(9)"/> </td> <td> <input id="bt12" type="button" value="*" onclick="addNum()"/> </td> </tr> <tr> <td> <input id="bt0" type="button" value="0" onclick="addNum(0)"/> </td> <td> <input id="bt13" type="button" value="." onclick="addNum()"/> </td> <td> <input id="bt14" type="button" value="%" onclick="addNum(1)"/> </td> <td> <input id="bt15" type="button" value="/" onclick="addNum()"/> </td> </tr> <tr> <td> <input id="bt16" type="button" value="C" onclick="addNum()"/> </td> <td> <input id="bt17" type="button" value="←" onclick="addNum()"/> </td> <td colspan="2"> <input id="bt18" type="button" value="=" onclick="addNum()"/> </td> </tr> </table> </div> </form> </center> </body> <script> for (var i = 0;i<19 ;i++ ) { document.getElementById("bt"+i).style.width="140px"; document.getElementById("bt"+i).style.height="90px"; document.getElementById("bt"+i).style.fontSize="80px" document.getElementById("bt"+i).className= "mr"//默认状态按键颜色 document.getElementById("bt"+i).onmouseover = function(){this.className= "jr"};//匿名函数(鼠标进入事件) document.getElementById("bt"+i).onmouseout = function(){this.className= "mr"};//鼠标移出事件(默认事件) document.getElementById("bt"+i).onmousedown = function(){this.className= "ax"};//鼠标按下事件 document.getElementById("bt"+i).onmouseup = function(){this.className= "fk"};//鼠标放开事件 } document.getElementById("bt18").style.width="286px"; document.getElementById("num").style.width="580px"; document.getElementById("num").style.height="90px"; document.getElementById("num").style.fontSize="70px"; </script> </html> </code></pre>解决 无用评论 打赏 举报
悬赏问题
- ¥15 训练的多模态特征融合模型准确度很低怎么办
- ¥15 kylin启动报错log4j类冲突
- ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
- ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
- ¥15 onvif+openssl,vs2022编译openssl64
- ¥15 iOS 自定义输入法-第三方输入法
- ¥15 很想要一个很好的答案或提示
- ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
- ¥15 怀疑手机被监控,请问怎么解决和防止
- ¥15 Qt下使用tcp获取数据的详细操作