<!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=gb2312" />
<title>计算器</title>
<style type="text/css">
input {
width: 50px;
margin: 5px
}
</style>
<script type="text/javascript" defer="defer">
function add(s){
var t=document.getElementById("text");
switch(s){
case '+':
case '-':
case '*':
case '/':
if(t.value==''){
t.value='0'+'\n'+s;
}else{
t.value+='\n'+s;
}
break;
case '=':
t.value=eval(t.value.replace(/<[^>]*>|\n/igm,''))
break;
case 'c':
t.value='0';
break;
case 'ce':
tt.value=t.value.substr(0,t.value.length-1)
break;
default:
if(t.value=='0'){
t.value=s;
}else{
if(t.value.substr(t.value.length-1,1).match(/[\+\-\*\/]$/igm)){
t.value+='\n'+s;
}else{
t.value+=''+s;
}
}
}
}
</script>
</head>
<body>
<div>
<textarea id="text" style="width: 200px; height: 100px">0</textarea>
<input type="button" value="1" οnclick="add(1)" />
<input type="button" value="2" οnclick="add(2)" />
<input type="button" value="3" οnclick="add(3)" />
<input type="button" value="4" οnclick="add(4)" />
<input type="button" value="5" οnclick="add(5)" />
<input type="button" value="6" οnclick="add(6)" />
<input type="button" value="7" οnclick="add(7)" />
<input type="button" value="8" οnclick="add(8)" />
<input type="button" value="9" οnclick="add(9)" />
<input type="button" value="0" οnclick="add(0)" />
<input type="button" value="." οnclick="add('.')" />
<input type="button" value="+" οnclick="add('+')" />
<input type="button" value="-" οnclick="add('-')" />
<input type="button" value="*" οnclick="add('*')" />
<input type="button" value="/" οnclick="add('/')" />
<input type="button" value="=" οnclick="add('=')" />
<input type="button" value="c" οnclick="add('c')" />
<input type="button" value="ce" οnclick="add('ce')" />
</div>
</body>
</html>
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/ html; charset=gb2312" />
<title>计算器</title>
<style type="text/css">
input {
width: 50px;
margin: 5px
}
</style>
<script type="text/javascript" defer="defer">
function add(s){
var t=document.getElementById("text");
switch(s){
case '+':
case '-':
case '*':
case '/':
if(t.value==''){
t.value='0'+'\n'+s;
}else{
t.value+='\n'+s;
}
break;
case '=':
t.value=eval(t.value.replace(/<[^>]*>|\n/igm,''))
break;
case 'c':
t.value='0';
break;
case 'ce':
tt.value=t.value.substr(0,t.value.length-1)
break;
default:
if(t.value=='0'){
t.value=s;
}else{
if(t.value.substr(t.value.length-1,1).match(/[\+\-\*\/]$/igm)){
t.value+='\n'+s;
}else{
t.value+=''+s;
}
}
}
}
</script>
</head>
<body>
<div>
<textarea id="text" style="width: 200px; height: 100px">0</textarea>
<input type="button" value="1" οnclick="add(1)" />
<input type="button" value="2" οnclick="add(2)" />
<input type="button" value="3" οnclick="add(3)" />
<input type="button" value="4" οnclick="add(4)" />
<input type="button" value="5" οnclick="add(5)" />
<input type="button" value="6" οnclick="add(6)" />
<input type="button" value="7" οnclick="add(7)" />
<input type="button" value="8" οnclick="add(8)" />
<input type="button" value="9" οnclick="add(9)" />
<input type="button" value="0" οnclick="add(0)" />
<input type="button" value="." οnclick="add('.')" />
<input type="button" value="+" οnclick="add('+')" />
<input type="button" value="-" οnclick="add('-')" />
<input type="button" value="*" οnclick="add('*')" />
<input type="button" value="/" οnclick="add('/')" />
<input type="button" value="=" οnclick="add('=')" />
<input type="button" value="c" οnclick="add('c')" />
<input type="button" value="ce" οnclick="add('ce')" />
</div>
</body>
</html>