求补全代码(网页类),简易计算器
本帖最后由 幻之律 于 2022-12-20 09:07 编辑<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<styletype="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=1234;
}
</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>
<tdheight="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=""/>
<input name="btnMul" type="button" value=" * " onclick=""/>
<input name="btnDiv" type="button" value=" ÷ " onclick=""/>
</td>
</tr>
<tr>
<tdheight="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> <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<styletype="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>
<tdheight="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>
<tdheight="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>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<styletype="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;
var result = parseFloat(a) + parseFloat(b);
document.getElementById("txtResult").value=result;
}
function subtract() {
var a = document.getElementById("txtNum1").value;
var b = document.getElementById("txtNum2").value;
var result = parseFloat(a) - parseFloat(b);
document.getElementById("txtResult").value = result;
}
function multiply() {
var a = document.getElementById("txtNum1").value;
var b = document.getElementById("txtNum2").value;
var result = parseFloat(a) * parseFloat(b);
document.getElementById("txtResult").value = result;
}
function divide() {
var a = document.getElementById("txtNum1").value;
var b = document.getElementById("txtNum2").value;
var result = parseFloat(a) / parseFloat(b);
document.getElementById("txtResult").value = result;
}
</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>
<tdheight="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="subtract()"/>
<input name="btnMul" type="button" value=" * " onclick="multiply()"/>
<input name="btnDiv" type="button" value=" ÷ " onclick="divide()"/>
</td>
</tr>
<tr>
<tdheight="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> 感谢帮助 简单的计算器,用这个代码基本能实现 非常基础的开发练习,感谢分享
页:
[1]