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 onload="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" 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> 
    <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月前
|
前端开发
html空格代码怎么写
HTML中的空格可以通过多种方式实现,这取决于你想要在页面上显示的空格类型。以下是一些常用的方法来在HTML中创建空格
|
1月前
|
移动开发 前端开发 JavaScript
编程笔记 html5&css&js 005 网页上都有哪内容、形式和操作
编程笔记 html5&css&js 005 网页上都有哪内容、形式和操作
|
2天前
|
前端开发
HTML代码示例
HTML代码示例
10 1
|
2天前
|
搜索推荐
当使用HTML代码时,一些常见的问题
当使用HTML代码时,一些常见的问题
7 0
|
3天前
错误或拦截页面的html代码
错误或拦截页面的html代码
3 0
错误或拦截页面的html代码
|
27天前
当当网首页——html代码
当当网首页——html代码
8 1
|
29天前
网状的隧道穿梭特效HTML代码
网状的隧道穿梭特效HTML代码,效果是动态的,可以下载源码,自己在本地运行
12 0
网状的隧道穿梭特效HTML代码
|
1月前
自适应窗口图片轮播HTML代码
自适应窗口图片轮播HTML代码
19 2
自适应窗口图片轮播HTML代码
|
1月前
|
搜索推荐 前端开发 JavaScript
打造个性化的个人网页:从HTML到个人品牌
打造个性化的个人网页:从HTML到个人品牌
20 0
|
1月前
|
前端开发 容器
html居中代码怎么写
在HTML和CSS中,居中元素是一个常见的布局需求。无论是文本、图片还是整个容器,居中都可以使页面看起来更加整洁和对称。以下是几种常用的HTML居中方法及其代码示例。