慕标2471974
2020-02-05 17:22
<!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>
<script type="text/javascript">
function count(){
var a=document.getElementById("text1").value ;
var b=document.getElementById("text2".value) ;
var c=document.getElementById("select").value ;
var sum = "" ;
switch(c){
case "+":
sum = parseInt(a) + parseInt(b);
break;
case "-":
sum= parseInt(a) - parseInt(b);
break;
case "*":
sum= parseInt(a) * parseInt(b);
break;
default:
sum= parseInt(a) / parseInt(b);
}
document.getElementById("sum1")=sum;
}
</script>
</head>
<body>
<input type="text" id="text1"/>
<select id="select">
<option value= "+" >+</option>
<option value= "-" >-</option>
<option value= "*" >*</option>
<option value= "/" >/</option>
</select>
<input type="text" id="text2"/>
<input type="button" value="计算" onclick="count()"/>
<input type="text" id="sum1"/>
</body>
</html>
document.getElementById("sum1")=sum;这句少了.value
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题