[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
table
{
border-collapse:collapse;
background-color:#a6a6d4;
width:500px;
}
.result
{
border:solid 1px #999999;
color:#FF0033;
font-family:Arial, Helvetica, sans-serif;
font-size:16px;
height:25px;
}
</style>
<script type="text/javascript">
function add()
{
var a=document.getElementById("txtNum1").value;
var b=document.getElementById("txtNum2").value;
document.getElementById("txtResult").value=parseInt(a)+parseInt(b);
}
function sub()
{
var a=document.getElementById("txtNum1").value;
var b=document.getElementById("txtNum2").value;
document.getElementById("txtResult").value=parseInt(a)-parseInt(b);
}
function mul()
{
var a=document.getElementById("txtNum1").value;
var b=document.getElementById("txtNum2").value;
document.getElementById("txtResult").value=parseInt(a)*parseInt(b);
}
function div()
{
var a=document.getElementById("txtNum1").value;
var b=document.getElementById("txtNum2").value;
document.getElementById("txtResult").value=parseInt(a)/parseInt(b);
}
</script>
</head>
<body>
<form name="myform">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="28" colspan="2" align="left" bgcolor="#1191FF" ></td>
</tr>
<tr>
<td height="43" colspan="2" align="center" bgcolor="#1191FF" > <h2>简易计算器</h2></td>
</tr>
<tr>
<td height="35" align="right">数值1:</td>
<td><input id="txtNum1" type="text" /></td>
</tr>
<tr>
<td height="35" align="right">数值2:</td>
<td><input id="txtNum2" type="text" /></td>
</tr>
<tr>
<td align="center" colspan="2" height="35">
<input name="btnAdd" type="button" value=" + " onclick="add()" />
<input name="btnSub" type="button" value=" - " onclick="sub()"/>
<input name="btnMul" type="button" value=" * " onclick="mul()"/>
<input name="btnDiv" type="button" value=" ÷ " onclick="div()"/>
</td>
</tr>
<tr>
<td height="50" align="right">计算结果:</td>
<td><input id="txtResult" type="text" class="result" /></td>
</tr>
<tr>
<td colspan="2" height="25" bgcolor="#1191FF">
</td>
</tr>
</table>
</form>
</body>
</html>
|