您的位置:首页 > Web前端 > JavaScript

网页计算器(javascript脚本)

2014-04-09 16:24 281 查看
<html>
<head>
<script>
var  s="";
function add(a)//连接输入字符
{
var t;
t=a.value;
s+=t;
cal.sr.value=s;
}
function rn()//计算
{
cal.rs.value=eval(s);
}
</script>
</head>
<body>
<center>
<form name="cal">
<input type="text"  style="{font-size:40px}" name="sr" value="" size=16> <br>
<input typt="text"  style="{font-size:40px}" name="rs" value="" size=16> <br>
<input type="button" value="7" name="b7" onclick="add(this)">
<input type="button" value="8" name="b8" onclick="add(this)">
<input type="button" value="9" name="b9" onclick="add(this)">
<input type="button" value="+" name="bjia" onclick="add(this)"> <br>
<input type="button" value="4" name="b4" onclick="add(this)">
<input type="button" value="5" name="b5" onclick="add(this)">
<input type="button" value="6" name="b6" onclick="add(this)">
<input type="button" value="-" name="bjian" onclick="add(this)"> <br>
<input type="button" value="1" name="b1" onclick="add(this)">
<input type="button" value="2" name="b2" onclick="add(this)">
<input type="button" value="3" name="b3" onclick="add(this)">
<input type="button" value="*" name="bcheng" onclick="add(this)"> <br>
<input type="button" value="." name="bdian" onclick="add(this)">
<input type="submit" value="C" name="del">
<input type="button" value="=" name="bd" onclick="rn()">
<input type="button" value="/" name="bchu" onclick="add(this)"> <br>
</form>
</center>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: