HTML网页之计算器代码

计算器网页效果显示:点击这里!



<script> 
function show(){ 
var date = new Date(); //日期对象 
var now = ""; 
now = date.getFullYear()+"年"; //读英文就行了 
now = now + (date.getMonth()+1)+"月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了 
now = now + date.getDate()+"日"; 
now = now + date.getHours()+"时"; 
now = now + date.getMinutes()+"分"; 
now = now + date.getSeconds()+"秒"; 
document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串 
setTimeout("show()",1000); //设置过1000毫秒就是1秒,调用show方法 

</script>


<!DOCTYPE html> 
<html> 
<meta http-equiv="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> 


<style type="text/css">
img{
  position:absolute;
  left:1100px;
  top:100px;
  }
</style>
</head> 
<body>   <!用来显示时间>
<h2 align=right><font color="#cc0033">
<body οnlοad="show()">   <!-- 网页加载时调用一次 以后就自动调用了--> 
<div id="nowDiv"></div> 
</font></h2>
</body>
<body bgcolor="#9900ff" > 
<a  href="../index.html"><img border="0" src="./image/4.jpg" alt="主页面" title="返回主页面"></a>


<font color="red" size="6"><center>网络人VS灰鸽子工作室</center></font>
<p></p>
<!--定义按键表格,每个按键对应一个事件触发--> 
<table border="1" align="center" bgColor="#6633CC" 
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" οnclick="onclicknum(1)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="2" id="2" οnclick="onclicknum(2)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="3" id="3" οnclick="onclicknum(3)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="+" id="add" οnclick="onclicknum('+')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="button" value="4" id="4" οnclick="onclicknum(4)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="5" id="5" οnclick="onclicknum(5)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="6" id="6" οnclick="onclicknum(6)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="-" id="sub" οnclick="onclicknum('-')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="button" value="7" id="7" οnclick="onclicknum(7)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="8" id="8" οnclick="onclicknum(8)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="9" id="9" οnclick="onclicknum(9)" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="*" id="mul" οnclick="onclicknum('*')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td colspan="2"> 
<input type="button" value="0" id="0" οnclick="onclicknum(0)" 
style="height: 70px; width: 190px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="." id="point" οnclick="onclicknum('.')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
<td> 
<input type="button" value="/" id="division" 
οnclick="onclicknum('/')" 
style="height: 70px; width: 90px; font-size: 35px"> 
</td> 
</tr> 
<tr> 
<td colspan="2"> 
<input type="button" value="Del" id="clear" 
οnclick="onclickclear()" 
style="height: 70px; width: 190px; font-size: 35px" /> 
</td> 
<td colspan="2"> 
<input type="button" value="=" id="result" 
οnclick="onclickresult()" 
style="height: 70px; width: 190px; font-size: 35px" /> 
</td> 
</tr> 
</table> 
    <font size="5" color="ff99ff">Design by:<a target="_blank" href="http://blog.csdn.net/qq_21792169/article/details/50629515" >网络人VS灰鸽子</a> 2016-3-3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;邮箱:linux_drv@yeah.net</font>

<! 这里为了方便我就直接添加空格来布局了,这里可以使用style>
</body> 
</html> 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值