<!DOCTYPE html>
<html lang="en" >
<head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>计算器</title>
<style>
.all{
margin:0px auto;
width:270px;
height:250px;
border:2px solid green;
background:yellow;
}
.screen{
width:258px;
height:38px;
text-align: right;
padding-right:10px;
font-size:20px;
}
.buttons{
width:50px;
height:50px;
border:1px solid black;
}
</style>
</head>
<body οnlοad="onLoad()">
<div class="all">
<!--screen输入栏-->
<div class="screen">
<input type="text" id="screenName" name="screenName" class="screen" value="" οnfοcus="jsq(this)">
</div>
<!-- operators and other keys -->
<!--第一排-->
<table>
<tr><td><input type="button" id="7" οnclick="jsq(this.id)" value="7" class="buttons"></td>
<td><input type="button" id="8" οnclick="jsq(this.id)" value="8" class="buttons"></td>
<td><input type="button" id="9" οnclick="jsq(this.id)" value="9" class="buttons"></td>
<td><input type="button" id="del" οnclick="tuiGe()" value="del" class="buttons"></td>
<td><input type="button" id="C" οnclick="clearNum()" value="清零" class="buttons" style="margin-right:0px"></td></tr>
<!--第二排-->
<tr><td><input type="button" id="4" οnclick="jsq(this.id)" value="4" class="buttons"></td>
<td><input type="button" id="5" οnclick="jsq(this.id)" value="5" class="buttons"></td>
<td><input type="button" id="6" οnclick="jsq(this.id)" value="6" class="buttons"></td>
<td><input type="button" id="*" οnclick="jsq(this.id)" value="*" class="buttons"></td>
<td><input type="button" id="/" οnclick="jsq(this.id)" value="/" class="buttons" style="margin-right:0px"></td></tr>
<!--第三排-->
<tr><td><input type="button" id="1" οnclick="jsq(this.id)" value="1" class="buttons"></td>
<td><input type="button" id="2" οnclick="jsq(this.id)" value="2" class="buttons"></td>
<td><input type="button" id="3" οnclick="jsq(this.id)" value="3" class="buttons"></td>
<td><input type="button" id="+" οnclick="jsq(this.id)" value="+" class="buttons"></td>
<td><input type="button" id="-" οnclick="jsq(this.id)" value="-" class="buttons" style="margin-right:0px"></td></tr>
<!--第四排-->
<tr><td><input type="button" id="0" οnclick="jsq(this.id)" value="0" class="buttons"></td>
<td><input type="button" id="." οnclick="jsq(this.id)" value="." class="buttons"></td>
<td><input type="button" id="%" οnclick="jsq(this.id)" value="%" class="buttons"></td>
<td><input type="button" id="eva" οnclick="eva()" value="=" class="buttons" style="margin-right:0px"></td>
<td><input type="button" id="sqrt" οnclick="s()" value="根号" class="buttons"></td>
</tr>
</table>
</div>
</body>
<script>
var num = 0; // 定义第一个输入的数据
function jsq(num) {
//获取当前输入
document.getElementById('screenName').value += document.getElementById(num).value;
}
function eva() {
//计算输入结果
document.getElementById("screenName").value = eval(document.getElementById("screenName").value);
}
function s(){
var a=parseFloat(document.getElementById("screenName").value)
b=Math.sqrt(a);
document.getElementById("screenName").value =b;
document.getElementById("screenName").focus();
}
//开根号
function clearNum() {
//清0
document.getElementById("screenName").value = null;
document.getElementById("screenName").focus();
}
function tuiGe() {
//退格
var arr = document.getElementById("screenName");
arr.value = arr.value.substring(0, arr.value.length - 1);
}
function onLoad(){
//加载完毕后光标自动对应到输入框
document.getElementById("screenName").focus();
}
/**
* ┏┓ ┏┓
* ┏┛┻━━━------┛ ┻┓
* ┃ ┃
* ┃ ━ ┃
* ┃ ┳┛ ┗┳ ┃
* ┃ ┃
* ┃ ┻ ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━ ┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
* 神兽保佑
* 代码无BUG!
*/
</script>
</html>
<html lang="en" >
<head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>计算器</title>
<style>
.all{
margin:0px auto;
width:270px;
height:250px;
border:2px solid green;
background:yellow;
}
.screen{
width:258px;
height:38px;
text-align: right;
padding-right:10px;
font-size:20px;
}
.buttons{
width:50px;
height:50px;
border:1px solid black;
}
</style>
</head>
<body οnlοad="onLoad()">
<div class="all">
<!--screen输入栏-->
<div class="screen">
<input type="text" id="screenName" name="screenName" class="screen" value="" οnfοcus="jsq(this)">
</div>
<!-- operators and other keys -->
<!--第一排-->
<table>
<tr><td><input type="button" id="7" οnclick="jsq(this.id)" value="7" class="buttons"></td>
<td><input type="button" id="8" οnclick="jsq(this.id)" value="8" class="buttons"></td>
<td><input type="button" id="9" οnclick="jsq(this.id)" value="9" class="buttons"></td>
<td><input type="button" id="del" οnclick="tuiGe()" value="del" class="buttons"></td>
<td><input type="button" id="C" οnclick="clearNum()" value="清零" class="buttons" style="margin-right:0px"></td></tr>
<!--第二排-->
<tr><td><input type="button" id="4" οnclick="jsq(this.id)" value="4" class="buttons"></td>
<td><input type="button" id="5" οnclick="jsq(this.id)" value="5" class="buttons"></td>
<td><input type="button" id="6" οnclick="jsq(this.id)" value="6" class="buttons"></td>
<td><input type="button" id="*" οnclick="jsq(this.id)" value="*" class="buttons"></td>
<td><input type="button" id="/" οnclick="jsq(this.id)" value="/" class="buttons" style="margin-right:0px"></td></tr>
<!--第三排-->
<tr><td><input type="button" id="1" οnclick="jsq(this.id)" value="1" class="buttons"></td>
<td><input type="button" id="2" οnclick="jsq(this.id)" value="2" class="buttons"></td>
<td><input type="button" id="3" οnclick="jsq(this.id)" value="3" class="buttons"></td>
<td><input type="button" id="+" οnclick="jsq(this.id)" value="+" class="buttons"></td>
<td><input type="button" id="-" οnclick="jsq(this.id)" value="-" class="buttons" style="margin-right:0px"></td></tr>
<!--第四排-->
<tr><td><input type="button" id="0" οnclick="jsq(this.id)" value="0" class="buttons"></td>
<td><input type="button" id="." οnclick="jsq(this.id)" value="." class="buttons"></td>
<td><input type="button" id="%" οnclick="jsq(this.id)" value="%" class="buttons"></td>
<td><input type="button" id="eva" οnclick="eva()" value="=" class="buttons" style="margin-right:0px"></td>
<td><input type="button" id="sqrt" οnclick="s()" value="根号" class="buttons"></td>
</tr>
</table>
</div>
</body>
<script>
var num = 0; // 定义第一个输入的数据
function jsq(num) {
//获取当前输入
document.getElementById('screenName').value += document.getElementById(num).value;
}
function eva() {
//计算输入结果
document.getElementById("screenName").value = eval(document.getElementById("screenName").value);
}
function s(){
var a=parseFloat(document.getElementById("screenName").value)
b=Math.sqrt(a);
document.getElementById("screenName").value =b;
document.getElementById("screenName").focus();
}
//开根号
function clearNum() {
//清0
document.getElementById("screenName").value = null;
document.getElementById("screenName").focus();
}
function tuiGe() {
//退格
var arr = document.getElementById("screenName");
arr.value = arr.value.substring(0, arr.value.length - 1);
}
function onLoad(){
//加载完毕后光标自动对应到输入框
document.getElementById("screenName").focus();
}
/**
* ┏┓ ┏┓
* ┏┛┻━━━------┛ ┻┓
* ┃ ┃
* ┃ ━ ┃
* ┃ ┳┛ ┗┳ ┃
* ┃ ┃
* ┃ ┻ ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━ ┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
* 神兽保佑
* 代码无BUG!
*/
</script>
</html>