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

为什么没有答案?求解

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html charset=utf-8">

<title>计算器</title>

//计算函数

<script type="text/javascript">

function count(){

var n1=document.getElementById("num1").value;

var n2=document.getElementById("num2").value;

var n=document.getElementById("select").value;

var count="";

swicth(n){

case "+": 

count=parseFloat(n1)+parseFloat(n2);

break;

case "-": 

count=parseFloat(n1)-parseFloat(n2);

break;

case "*":

count=parseFloat(n1)*parseFloat(n2);

break;

case "/":

count=parseFloat(n1)/parseFloat(n2);

break;

}

document.getElementById("fruit").value=count;

}

</script>

</head>

<body>

<form>

//界面显示

<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="count()" /><br/>

<input type="text" id="fruit" />

</form>

</body>

</html>


提问者:慕粉1010084486 2018-08-01 10:31

个回答

  • 挽安0
    2018-08-01 16:00:55

    swicth写错了 是switch