如何利用BQ里面的vb脚本做计算器,实现加减乘除的连算。例如:1+2+3-1*3/2

如题所述

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>计算器</title>
</head>
<script language="javascript">
var op1,op2,opcode,result;
function getcodeadd()
{
opcode="+";
}
function getcodede()
{
opcode="-";
}
function getcodep1()
{
opcode="*";
}
function getcodedi()
{
opcode="/";
}
function count()
{
op1=parseFloat(document.getElementById("op1").value);
op2=parseFloat(document.getElementById("op2").value);
if(opcode=="+")
{document.getElementById("result").value=op1+op2;}
if(opcode=="-")
{document.getElementById("result").value=op1-op2;}
if(opcode=="*")
{document.getElementById("result").value=op1*op2;}
if(opcode=="/")
{document.getElementById("result").value=op1/op2;}

}
</script>
<body>
<table border="1" bgcolor="#3399FF">
<tr> <td height="60" colspan="3" ><b>计算器</b></td></tr>
<tr> <td width="140" height="38">   第一个数</td>
<td width="216"> <input id="op1" type="text" size="14"/></td>
<td width="44" rowspan="3"><label>
<input type="submit" name="button1" id="button1" value="+" onclick="getcodeadd()"/>
<input type="submit" name="button2" id="button2" value="-" onclick="getcodede()"/>
<input type="submit" name="button3" id="button3" value="*" onclick="getcodep1()"/>
<input type="submit" name="button4" id="button4" value="/" onclick="getcodedi()"/>
</label></td>
</tr>
<tr> <td width="140" height="33">   第二个数</td>
<td width="216"> <input id="op2" type="text" size="14"/></td>
</tr>
<tr> <td width="140" height="36">   计算结果</td>
<td width="216"> <input id="result" type="text" size="14" onclick="count()"/></td>
</tr>
</table>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网