批改状态:合格
老师批语:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>简单计算器</title></head><body><input type="text" id="shu1" size="7"><select id="ys"><option>+</option><option>-</option><option>*</option><option>/</option><option>%</option></select><input type="text" id="shu2" size="7"><button type="button" id="js" value="btn">=</button><p id="jg">结果:</p><script>document.getElementById("js").onclick =function(){var shu1 = document.getElementById("shu1").value;var shu2 = document.getElementById("shu2").value;var ys = document.getElementById("ys").value;var zhjg =true;if(shu1==''||shu2==''){alert('输入框不能为空');return;}if(zhjg){switch(ys){case '+' :result = "结果:" + ((parseFloat(shu1)*100 + parseFloat(shu2)*100)/100);break;case '-' :result = "结果:" + (shu1 - shu2);break;case '*' :result = "结果:" + (shu1 * shu2);break;case '/' :if(shu2==0){result ="除数不能为0"}else{result = "结果:" + (shu1 / shu2);}break;case '%' :if(shu2==0){result ="除数不能为0"}else{result = "结果:" + (shu1 % shu2);}break;}}document.getElementById('jg').innerHTML=result;}</script></body></html>



Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号