问答详情
源自:6-11 编程练习

请大家帮帮忙看哪里有问题,总是算不出结果嘞

<!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>


提问者:一只想周游世界的小蜗牛 2017-02-12 14:41

个回答

  • weibo_学会一切去爱你_0
    2017-02-12 15:16:24
    已采纳

    do函数名实关键字吧,用别的名字