<body>
<form action="" method="post">
<input type="number" id="num1" />
<select id="ysf">
<option value="+" id="+">+</option>
<option value="-" id="-">-</option>
<option value="*" id="*">*</option>
<option value="/" id="/">/</option>
<option value="%" id="%">%</option>
</select>
<input type="number" id="num2" />
<input type="button" value="计算" id="btn" />
</form>
<p id="res"></p>
<script>
document.getElementById("btn").onclick = function () {
var num1 = document.getElementById("num1").value;
var num2 = document.getElementById("num2").value;
var ysf = document.getElementById("ysf").value;
document.getElementById("res").innerHTML = num1 + "---" + num2 + "---" + ysf;
var res = document.getElementById("res");
var fh = ysf;
switch (ysf) {
case document.getElementById("+").value:
res.innerHTML = num1 + ysf + num2 + "=" + (num1 * 1 + num2 * 1);
console.log(ysf);
break;
case document.getElementById("-").value:
res.innerHTML = num1 + ysf + num2 + "=" + (num1 * 1 - num2 * 1);
console.log(ysf);
break;
case document.getElementById("*").value:
res.innerHTML = num1 + ysf + num2 + "=" + num1 * 1 * num2 * 1;
break;
case document.getElementById("/").value:
res.innerHTML = num1 + ysf + num2 + "=" + num1 / num2;
break;
case document.getElementById("%").value:
res.innerHTML = num1 + ysf + num2 + "=" + (num1 % num2);
break;
}
};
document.write('<table border="1" width="800px" align=center >');
for (var hang = 1; hang <= 9; hang++) {
document.write("<tr>");
for (var lie = 1; lie <= hang; lie++) {
document.write("<td>" + lie + "*" + hang + "=" + hang * lie + "</td> ");
}
document.write("</tr>");
}
</script>
成品图:
<script>
document.write('<table border="1" width="800px" align=center >');
for (var hang = 1; hang <= 9; hang++) {
document.write("<tr>");
for (var lie = 1; lie <= hang; lie++) {
document.write("<td>" + lie + "*" + hang + "=" + hang * lie + "</td> ");
}
document.write("</tr>");
}
</script>
附成品图:
相关推荐
© 2020 asciim码
人生就是一场修行