姜伟猎场小说txt云盘:html 简单计算

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 19:11:30
本人对html没什么研究。现在想实现这样一个功能:一个网页中有三个文本框,让浏览者输入两个数值m,n,然后计算m*100+n*10并在第三个文本框里面显示出来!!
该如何实现?如果用java Script该怎么写?
谢!!
知道问题有点白,但是希望你对我这个菜鸟心细些!!
写出完整的的html代码!!
快啊!!

还有啊!!你的代码乘法可以,怎么加的时候就是简单罗列?
象1+2=12!!

代码如下: 
<!DOCTYPE html> 
<html> 
<meta name="content-type" content="text/html; charset=UTF-8"> 
<head> 
<title>Calculator</title> 
<!--将按键内容以字符串形式存储在文字框中当按钮为“=”时,调用eval方法计算结果然后将结果输出文字框中--> 
<script type="text/javascript"> 
var numresult; 
var str; 
function onclicknum(nums) { 
str = document.getElementById("nummessege"); 
str.value = str.value + nums; 

function onclickclear() { 
str = document.getElementById("nummessege"); 
str.value = ""; 

function onclickresult() { 
str = document.getElementById("nummessege"); 
numresult = eval(str.value); 
str.value = numresult; 

</script> 
</head> 
<body bgcolor="affff" > 
<!--定义按键表格,每个按键对应一个事件触发--> 
<table border="1" align="center" bgColor="#bbff77" 
style="height: 350px; width: 270px"> 
<tr> 
<td colspan="4"> 
<input type="text" id="nummessege" 
style="height: 90px; width: 350px; font-size: 50px" /> 
</td> 
</tr> 
<tr> 
<td> 
<input type="button" value="1" id="1" onclick="onclicknum(1)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="2" id="2" onclick="onclicknum(2)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="3" id="3" onclick="onclicknum(3)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="+" id="add" onclick="onclicknum('+')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="button" value="4" id="4" onclick="onclicknum(4)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="5" id="5" onclick="onclicknum(5)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="6" id="6" onclick="onclicknum(6)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="-" id="sub" onclick="onclicknum('-')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="button" value="7" id="7" onclick="onclicknum(7)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="8" id="8" onclick="onclicknum(8)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="9" id="9" onclick="onclicknum(9)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="*" id="mul" onclick="onclicknum('*')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td colspan="2"> 
<input type="button" value="0" id="0" onclick="onclicknum(0)" 
style="height: 70px; width: 190px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="." id="point" onclick="onclicknum('.')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="/" id="division" 
onclick="onclicknum('/')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td colspan="2"> 
<input type="button" value="Del" id="clear" 
onclick="onclickclear()" 
style="height: 70px; width: 190px; font-size: 35px" /> 
</td> 
<td colspan="2"> 
<input type="button" value="=" id="result" 
onclick="onclickresult()" 
style="height: 70px; width: 190px; font-size: 35px" /> 
</td> 

</tr> 

</table> 
</body> 
</html> 

我来给你一个完整的代码页面:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>

<body>

m:<input type="text" name="txt1" size="10">
n:<input type="text" name="txt2" size="10">
m*100+n*10<input type="text" name="txt3" size="10">
<input type="button" name="btn" value="计算" onclick="calculate();">
<script language="javascript">
function calculate(){
var m=new Number();
var n=new Number();
m=document.getElementById("txt1").value;
n=document.getElementById("txt2").value;
document.getElementById("txt3").value=m*100+n*10;
}
</script>
</body>

</html>

onclick="text3.value=text1.value+text2.value"

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<script language="javascript">
function calculate(){
//var m = new Number();
//var n = new Number();
var m = document.getElementById("txt1").value;
alert(m);
var n = document.getElementById("txt2").value;
document.getElementById("txt3").value = m*100+n*10;
}
</script>
</head>
<body>
m:<input type="text" id="txt1" size="10">
<br>
n:<input type="text" id="txt2" size="10">
<br>
m*100+n*10<input type="text" id="txt3" size="10">
<input type="button" name="btn" value="计算" onclick="calculate();">
</body>
</html>