<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>js简单计算器 - www.plcxue.com</title>
<script type="text/
javascript">
function sum() {
//js类型转换 parseInt(value,10) 将value的值转换成十进制的数值
var id1 = parseInt(document.getElementById("bnt1").value, 10);
var id2 = parseInt(document.getElementById("bnt2").value, 10);
var id3 = id1 + id2;
document.getElementById("bnt3").value = id3;
}
</script>
</head>
<body>
js计算器:
<input type="text" id ="bnt1" />+<input type="text" id="bnt2" />
<input type="button" value="=" onclick="sum()"/>
<input type="text"
readonly="readonly" id="bnt3" />
</body>
</html>