一只想周游世界的小蜗牛
2017-02-12 14:41
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>holiday review</title>
<script type="text/javascript">
function do(){
var num1=document.getElementById('num1').value;
var num2=document.getElementById('num2').value;
var result="";
var opt=document.getElementById('select').value;
switch(opt)
{
case "+":result=parseInt(num1)+parseInt(num2);
break;
case "-":result=parseInt(num1)-parseInt(num2);
break;
case "*":result=parseInt(num1)*parseInt(num2);
break;
case "/":result=parseInt(num1)/parseInt(num2);
break;
default:
break;
}
document.getElementById('result').value=result;
}
</script>
</head>
<body>
<input type='text' id='num1'/>
<select id='select'>
<option value='+'>+</option>
<option value='-'>-</option>
<option value='*'>*</option>
<option value='/'>/</option>
</select>
<input type='text' id='num2'/>
<input type='button' value="=" onclick="do()"/>
<input type='text' id='result'/>
</body>
</html>
do函数名实关键字吧,用别的名字
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题