weixin_慕虎7175654
2019-02-27 08:46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" id="txt1" />
<select id='select'>
<option value='+'>+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<div>
<input type="text" id="txt2" />
<button type="button" onclick="dengyu()">=</button>
</div>
<input type="text" id="txt3">
<script>
function dengyu(){
diyige=document.getElementById("txt1").value;
dierge=document.getElementById("txt2").value;
disange=document.getElementById("select").value;
switch(disange){
case"+":
document.getElementById("txt3").value=parseInt(diyige) + parseInt(dierge);
break;
case"-":
document.getElementById("txt3").value=diyige-dierge;
break;
case"*":
document.getElementById("txt3").value=diyige*dierge;
break;
case"/":
document.getElementById("txt3").value=diyige/dierge;
break;
}
}
</script>
</body>
</html>
可以啊,但是我觉得传参可能会好一丢丢吧
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题