jQuery在线文档说明https://jquery.cuishifeng.cn/index.html
文章引入的jQuery文件需单独下载,放置在JS文件下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
input{
width: 100px;
font-family: "仿宋";
}
.orange{
color: orange;
}
input:hover{
background-color: cyan;
margin: 0px;
}
div{
background-color: lawngreen;
width: 410px;
height: 140px;
position: absolute;
margin: auto;
left: 0px;
right: 0px;
}
</style>
</head>
<body>
<div>
<table border="0" cellspacing="0" cellpadding="0" width="400px">
<tr>
<td colspan="4">
<!-- margin外边距 -->
<input id = "output" type="text" readonly="readonly" style="width: 400px;text-align: right;margin: 1px;"/>
</td>
</tr>
<tr>
<td><input value="(" type="button" class="orange"></td>
<td><input value=")" type="button" class="orange"></td>
<td><input value="%" type="button" class="orange"></td>
<td><input value="C" type="button"></td>
</tr>
<tr>
<td><input value="7" type="button"></td>
<td><input value="8" type="button"></td>
<td><input value="9" type="button"></td>
<td><input value="/" type="button" class="orange"></td>
</tr>
<tr>
<td><input value="4" type="button"></td>
<td><input value="5" type="button"></td>
<td><input value="6" type="button"></td>
<td><input value="*" type="button" class="orange"</td>
</tr>
<tr>
<td><input value="1" type="button"></td>
<td><input value="2" type="button"></td>
<td><input value="3" type="button"></td>
<td><input value="-" type="button" class="orange"></td>
</tr>
<tr>
<td><input value="0" type="button"></td>
<td><input value="." type="button" class="orange"></td>
<td><input value="=" type="button" class="orange"></td>
<td><input value="+" type="button" class="orange"></td>
</tr>
</table>
</div>
</body>
<script type="text/javascript" src="js/jQuery/jquery-3.4.1.js">
</script>
<script type="text/javascript">
var output=$("#output");
var inputs=$(":button");
inputs.on("click",function(){
if(this.value==='C'){
output.val("");
}else if(this.value ==='='){
output.val(eval(output.val()));
}else{
output.val(output.val()+this.value);
}
});
</script>
</html>