<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- $Id: calculator.htm 14216 2008-03-10 02:27:21Z testyang $ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>计算器</title>
<script type="text/javascript">
/* $Id : utils.js 5052 2007-02-03 10:30:13Z weberliu $ */
var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);
var Utils = new Object();
Utils.htmlEncode = function(text)
{
return text.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
}
Utils.trim = function( text )
{
if (typeof(text) == "string")
{
return text.replace(/^s*|s*$/g, "");
}
else
{
return text;
}
}
Utils.isEmpty = function( val )
{
switch (typeof(val))
{
case 'string':
return Utils.trim(val).length == 0 ? true : false;
break;
case 'number':
return val == 0;
break;
case 'object':
return val == null;
break;
case 'array':
return val.length == 0;
break;
default:
return true;
}
}
Utils.isNumber = function(val)
{
var reg = /^[d|.|,]+$/;
return reg.test(val);
}
Utils.isInt = function(val)
{
if (val == "")
{
return false;
}
var reg = /D+/;
return !reg.test(val);
}
Utils.isEmail = function( email )
{
var reg1 = /([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)/;
return reg1.test( email );
}
Utils.isTel = function ( tel )
{
var reg = /^[d|-|s|_]+$/; //只允许使用数字-空格等
return reg.test( tel );
}
Utils.fixEvent = function(e)
{
var evt = (typeof e == "undefined") ? window.event : e;
return evt;
}
Utils.srcElement = function(e)
{
if (typeof e == "undefined") e = window.event;
var src = document.all ? e.srcElement : e.target;
return src;
}
Utils.isTime = function(val)
{
var reg = /^d{4}-d{2}-d{2}sd{2}:d{2}$/;
return reg.test(val);
}
Utils.x = function(e)
{ //当前鼠标X坐标
return Browser.isIE?event.x + document.documentElement.scrollLeft - 2:e.pageX;
}
Utils.y = function(e)
{ //当前鼠标Y坐标
return Browser.isIE?event.y + document.documentElement.scrollTop - 2:e.pageY;
}
Utils.request = function(url, item)
{
var sValue=url.match(new RegExp("[?&]"+item+"=([^&]*)(&?)","i"));
return sValue?sValue[1]:sValue;
}
Utils.$ = function(name)
{
return document.getElementById(name);
}
function rowindex(tr)
{
if (Browser.isIE)
{
return tr.rowIndex;
}
else
{
table = tr.parentNode.parentNode;
for (i = 0; i < table.rows.length; i ++ )
{
if (table.rows[i] == tr)
{
return i;
}
}
}
}
document.getCookie = function(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return decodeURIComponent(aCrumb[1]);
}
// a cookie with the requested name does not exist
return null;
}
document.setCookie = function(sName, sValue, sExpires)
{
var sCookie = sName + "=" + encodeURIComponent(sValue);
if (sExpires != null)
{
sCookie += "; expires=" + sExpires;
}
document.cookie = sCookie;
}
document.removeCookie = function(sName,sValue)
{
document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
function getPosition(o)
{
var t = o.offsetTop;
var l = o.offsetLeft;
while(o = o.offsetParent)
{
t += o.offsetTop;
l += o.offsetLeft;
}
var pos = {top:t,left:l};
return pos;
}
function cleanWhitespace(element)
{
var element = element;
for (var i = 0; i < element.childNodes.length; i++) {
var node = element.childNodes[i];
if (node.nodeType == 3 && !/S/.test(node.nodeValue))
element.removeChild(node);
}
}
</script>
<style type="text/css">
body, div, input {
font: 12px arial;
}
.calculatorButton {
text-align: center;
width: 73px;
}
.calculatorButton2 {
text-align: center;
width: 154px;
}
*+html .calculatorButton2 {
width: 157px;
}
#calculator .buttonArea {
padding: 3px;
border-color: #455690 #a6b4cf #a6b4cf #455690 ;
border-style: solid;
border-width: 1px;
}
#calculatorOutput {
padding: 2px; border:2px inset; margin: 2px;
}
#topbar{
position:absolute;
border-right: #455690 1px solid;
border-top: #a6b4cf 1px solid;
border-left: #a6b4cf 1px solid;
border-bottom: #455690 1px solid;
background-color: #c9d3f3;
width: 300px;
visibility: hidden;
z-index: 99999;
filter: progid:DXImageTransform.Microsoft.BasicImage(opacity=.65);
opacity: 0.65;
}
</style>
<script type="text/javascript">
<!--
var Calculator = Object();
Calculator.result = 0;
Calculator.current = '';
Calculator.values = 0;
Calculator.handle = '';
Calculator.elem = function(){ return document.getElementById('calculator'); };
Calculator.output = function() { return document.getElementById('calculatorOutput'); }
Calculator.input = function(n)
{
if (n == "."&& Calculator.current.toString().indexOf('.')>=0)
{
return;
}
var output = Calculator.output();
if (Calculator.current == "0" && n != ".") Calculator.current = '';
Calculator.current += "" + n;
output.innerHTML = Calculator.current;
}
Calculator.backspace = function()
{
var output = Calculator.output();
output.innerHTML = output.innerHTML.length > 1 ? output.innerHTML.substr(0, output.innerHTML.length-1) : 0;
Calculator.current = output.innerHTML;
}
Calculator.clear = function()
{
Calculator.result = 0;
Calculator.current = '';
Calculator.values = 0;
Calculator.handle = '';
var output = Calculator.output();
output.innerHTML = "0";
}
Calculator.calculate = function(p)
{
if (Calculator.handle != '' && Calculator.values != '' && Calculator.current != '')
{
try
{
var value = eval(Calculator.values + Calculator.handle + Calculator.current)
Calculator.values = value == 'Infinity' ? 0 : value;
Calculator.output().innerHTML = Calculator.values
}
catch (e)
{
alert(e);
}
}
else
{
Calculator.values = Calculator.current=='' ? Calculator.values : Calculator.current;
}
if (p == '=')
{
Calculator.output().innerHTML = Calculator.values == '' ? '0' : Calculator.values;
Calculator.current = Calculator.values;
Calculator.handle = '';
}
else
{
Calculator.handle = p;
}
Calculator.current = '';
}
onload = function() {
window.focus();
}
//-->
</script>
</head>
<body style="background:buttonFace">
<div class="buttonArea">
<div id="calculatorOutput" style="width:95%; text-align:right;border:2px inset;background:#FFF;">0</div>
<table width="100%">
<tr>
<td colspan="2"><input type="button" class="calculatorButton2" value="情初" onclick="Calculator.clear()" /></td>
<td colspan="2"><input type="button" class="calculatorButton2" value="退格" onclick="Calculator.backspace()" /></td>
</tr>
<tr>
<td><input class="calculatorButton" type="button" value="7" onclick="Calculator.input(7)" /></td>
<td><input type="button" value="8" class="calculatorButton" onclick="Calculator.input(8)" /></td>
<td><input type="button" value="9" class="calculatorButton" onclick="Calculator.input(9)" /></td>
<td><input type="button" value="/" class="calculatorButton" onclick="Calculator.calculate('/')" /></td>
</tr>
<tr>
<td><input type="button" value="4" class="calculatorButton" onclick="Calculator.input(4)" /></td>
<td><input type="button" value="5" class="calculatorButton" onclick="Calculator.input(5)" /></td>
<td><input type="button" value="6" class="calculatorButton" onclick="Calculator.input(6)" /></td>
<td><input type="button" value="*" class="calculatorButton" onclick="Calculator.calculate('*')" /></td>
</tr>
<tr>
<td><input type="button" value="1" class="calculatorButton" onclick="Calculator.input(1)" /></td>
<td><input type="button" value="2" class="calculatorButton" onclick="Calculator.input(2)" /></td>
<td><input type="button" value="3" class="calculatorButton" onclick="Calculator.input(3)" /></td>
<td><input type="button" value="-" class="calculatorButton" onclick="Calculator.calculate('-')" /></td>
</tr>
<tr>
<td><input type="button" value="0" class="calculatorButton" onclick="Calculator.input(0)" /></td>
<td><input type="button" value="." class="calculatorButton" onclick="Calculator.input('.')" /></td>
<td><input type="button" value="=" class="calculatorButton" onclick="Calculator.calculate('=')" /></td>
<td><input type="button" value="+" class="calculatorButton" onclick="Calculator.calculate('+')" /></td>
</tr>
<tr>
<td height="38"> </td>
<td colspan="2"><div align="center"><a href="#" onclick="top.close()">关闭窗口</a></div></td>
<td> </td>
</tr>
</table>
</div>
</body>
<script type="text/javascript">
<!--
document.onkeyup = function(e)
{
var evt = Utils.fixEvent(e);
if ((evt.keyCode >= 48 && evt.keyCode <= 57 && !evt.shiftKey) ||
(evt.keyCode >= 96 && evt.keyCode <= 105 && !evt.shiftKey))
{
if (evt.keyCode > 57)
{
Calculator.input(evt.keyCode - 96);
}
else
{
Calculator.input(evt.keyCode - 48);
}
}
else if ((evt.keyCode == 107 && !evt.shiftKey) || (evt.keyCode == 61 && evt.shiftKey) || (evt.keyCode == 187 && evt.shiftKey))
{
Calculator.calculate('+');
}
else if ((evt.keyCode == 109 && !evt.shiftKey) || (evt.keyCode == 189 && !evt.shiftKey))
{
Calculator.calculate('-');
}
else if ((evt.keyCode == 106 && !evt.shiftKey) || (evt.keyCode == 56 && evt.shiftKey))
{
Calculator.calculate('*');
}
else if ((evt.keyCode == 111 && !evt.shiftKey) || (evt.keyCode == 191 && !evt.shiftKey))
{
Calculator.calculate('/');
}
else if (evt.keyCode == 13 || (evt.keyCode == 61 && !evt.shiftKey) || (evt.keyCode == 187 && !evt.shiftKey))
{
Calculator.calculate('=');
}
else if ((evt.keyCode == 110 && !evt.shiftKey) || (evt.keyCode == 190 && !evt.shiftKey))
{
Calculator.input('.');
}
else if (evt.keyCode == 27)
{
Calculator.clear();
}
else if (evt.keyCode == 8)
{
Calculator.backspace();
}
return false;
//alert(evt.keyCode);
}
//-->
</script>
</html>
|