//九九乘法表
document.write('<table border="1" width="800" align="center">')
for(var hang = 1; hang <= 9; hang++){
document.write('<tr>')
for (var td =1; td <= hang; td++){
document.write('<td>' + td + 'X' + hang + '=' + ( td * hang ) + '</td>')
}
document.write('</tr>')
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>简单计算器</title>
<style>
div{
text-align: center;
font-size: 24px;
}
</style>
</head>
<body>
<div>
<input type="text" size="5" id="num1" value="">
<select id="ysf">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="%">%</option>
</select>
<input type="text" size="5" id="num2" value="">
<input type="button" value="计算" id="btn">
</div>
<div id="res"></div>
<script>
//获取按钮注册事件
document.getElementById('btn').onclick=function(){
var num1 = document.getElementById('num1').value;
var num2 = document.getElementById('num2').value;
var ysf = document.getElementById('ysf').value;
var res = document.getElementById('res')
//计算
switch(ysf){
case '+':
res.innerHTML = num1 + '+' + num2 + '=' + (num1*1 + num2*1);
break;
case '-':
res.innerHTML = num1 + '-' + num2 + '=' + (num1 - num2);
break;
case '*':
res.innerHTML = num1 + 'x' + num2 + '=' + (num1 * num2);
break;
case '/':
res.innerHTML = num1 + '÷' + num2 + '=' + (num1 / num2);
break;
case '%':
res.innerHTML = num1 + '%' + num2 + '=' + (num1 % num2);
break;
}
};
</script>
</body>
</html>
相关推荐
© 2020 asciim码
人生就是一场修行