幕布斯0495331
2019-11-15 15:19
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
var num1 = parseInt(document.getElementById("txt1").value);
var num2 = parseInt(document.getElementById("txt2").value);
var character = document.getElementById("select").value;
var result;
if(character=="+"){
result = num1+num2;
}
else if(character=="-"){
result = num1-num2;
}
else if(character=="*"){
result = num1*num2;
}
else if(character=="/"){
result = num1/num2;
}
else{
result = null;
}
document.getElementById("fruit").value = result;
}
</script>
</head>
<body>
<input type = "text" id = "txt1"/>
<select id = "select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type = "text" id = "txt2"/>
<input type = "button" value = "=" onClick="count()"/>
<input type = "text" id = "fruit"/>
</body>
</html>
有什么问题吗?
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题