<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算器</title>
<script type="text/javascript">
window.onload = function(){
var oX = document.getElementById("x");
var oSe = document.getElementById("se");
var oY = document.getElementById("y");
var oBt1 = document.getElementById("bt1");
oBt1.onclick=jS;
function jS(){
var oSee = oSe.value;
var ovalue1 = oX.value;
var ovalue2 = oY.value;
if (ovalue1 =="" || ovalue2 == "") {
alert("不能为空")
}else if (isNaN(ovalue1) || isNaN(ovalue2)) {
alert("请输入数字!")
}else{
if (oSee == "+") {
alert(((parseFloat(ovalue1)*100)+(parseFloat(ovalue2)*100))/100);
}else if (oSee == "-") {
alert(((parseFloat(ovalue1)*100)-(parseFloat(ovalue2)*100))/100);
}else if (oSee == "*") {
alert(((parseFloat(ovalue1)*100)*(parseFloat(ovalue2)*100))/10000);
}else if (oSee == "/") {
alert((parseFloat(ovalue1)*100)/(parseFloat(ovalue2)*100));
}
}
}
}
</script>
</head>
<body>
<h1 class="bt">计算器</h1>
<div class="bd">
<input type="text" id="x">
<select name="" id="se">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<!-- <input type="select" class="xy"> -->
<input type="text" id="y">
<button id="bt1">计算</button>
</div>
</body>
</html>
image.png
image.png
image.png
image.png
image.png
image.png
网友评论