<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>欣大胖的计算器</title>
<script>
window.onload = function()
{
document.getElementById("text1").focus();
}
function check(text1){
var r=document.form.expression.value
if(r==0&r!=""){//isNaN也行的,正则可以随意扩展!r.test
document.getElementById("hh").className="xs";
document.form.result.value="嘿!大侠!快停下来";
//alert('大侠请跟我说说0和字母开头的意义');
}else{
document.form.result.value="";
document.getElementById("hh").className="yc"
}
}
function set(sign){
document.form.expression.value+=sign;
}
function cal(){
document.form.result.value=eval(document.form.expression.value);
}
function clearText(){
document.form.expression.value="";
document.form.result.value="";
}
function backspace(){
var str=document.form.expression.value;
var len=str.length;
str=str.substring(0,len-1);
document.form.expression.value=str;
}
function changeSymbol(){
var num=parseFloat(document.form.expression.value);
num*=-1;
document.form.expression.value=num;
}
function keyLogin(){
if (event.keyCode==13) //回车键的键值为13
document.getElementById("input1").click(); //调用登录按钮的登录事件
// cal();
}
</script>
<style>
input{background-color:transparent;width:100px;height:50px; font-size:30px }
input.box{background-color:transparent;color:black;height:40px;width:350px;align:right;}
body{align:center}
.yc{
display:none;
}
#xs{
position:absolute;
font-size:500px
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
div{
position:fixed;
left:80px;
}
body{
background-image:url(14.jpg);background-position:absolute; width:100%; height:80%;background-size:cover; bottom:50px;background-repeat:repeat-y;
}
</style>
</head>
<body onkeydown=keyLogin();>
<div>
<h><font size="100px" color="blue" >大胖欣的计算器</font></h>
<form name="form">
<p><input type="text" name="expression" class="box" id="text1" onpropertychange='check(this.value)' oninput='check(this.value)' /></p>
<p><input type="text" name="result" class="box" /></p>
<p>
<input type="button" value="CE" onclick="clearText();" />
<input type="button" value="C" onclick="clearText();" />
<input type="button" value="B" onclick="backspace();" />
<input type="button" value="/" onclick="set('/');" />
</p>
<p>
<input type="button" value="7" onclick="set(7);" />
<input type="button" value="8" onclick="set(8);" />
<input type="button" value="9" onclick="set(9);" />
<input type="button" value="*" onclick="set('*');" />
</p>
<p>
<input type="button" value="4" onclick="set(4);" />
<input type="button" value="5" onclick="set(5);" />
<input type="button" value="6" onclick="set(6);" />
<input type="button" value="-" onclick="set('-');" />
</p>
<p>
<input type="button" value="1" onclick="set(1);" />
<input type="button" value="2" onclick="set(2);" />
<input type="button" value="3" onclick="set('3');" />
<input type="button" value="+" onclick="set('+');" />
</p>
<p>
<input type="button" value="-+" onclick="changeSymbol();" />
<input type="button" value="0" onclick="set(0);" />
<input type="button" value="." onclick="set('.');" />
<input type="button" value="=" id="input1" onclick="cal();" />
</p>
<div id="hh" class="yc" style="padding-left:400px; padding-top:60px; height:60px; width:800px "><font size="20px" color="red" >欣大胖!请说说0或字母开头数字的意义</font></div>
</form>
</body>
</html>