qq_潮哥_1
2018-10-09 15:45
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
var txts1 = parseInt(document.getElementById("txt1").value);
var txts2 =parseInt(document.getElementById("txt2").value);
var options =document.getElementById("select").value;
switch(options){
case "+":
var nim = parseInt(txts1) + parseInt(txts2);
break;
case "-";
var nim= parseInt(txts1)-parseInt(txts2);
break;
var nim=parseInt(txts1)* parseInt(txts2);
break;
var nim=parseInt(txts1)/parseInt(txts2);
break;
default;
}
document.getElementById("fruit").value=nim;
}
</script>
</head>
<body>
<input type='text' id='txt1' />
<select id='select'>
<option value='+'>+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type='text' id='txt2' />
<input type='button' value=' = ' onclick="count()"/> <!--通过 = 按钮来调用创建的函数,得到结果-->
<input type='text' id='fruit' />
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
var txts1 = parseInt(document.getElementById("txt1").value);
var txts2 =parseInt(document.getElementById("txt2").value);
var options =document.getElementById("select").value;
switch(options){
case "+":
var nim = txts1 + txts2;
break;
case "-":
var nim = txts1 - txts2;
break;
case "*":
var nim = txts1 * txts2;
break;
case "/":
var nim = txts1 / txts2;
break;
}
document.getElementById("fruit").value=nim;
}
</script>
</head>
<body>
<input type='text' id='txt1' />
<select id='select'>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type='text' id='txt2' />
<input type='button' value=' = ' onclick="count()"/>
<input type='text' id='fruit' />
</body>
</html>
楼上说得对
switch/case那里写的有问题
switch(options){
case "+":
var nim = parseInt(txts1)+parseInt(txts2);
break;
case "-":
var nim= parseInt(txts1)-parseInt(txts2);
break;
case "*":
var nim=parseInt(txts1)* parseInt(txts2);
break;
default:
var nim=parseInt(txts1)/parseInt(txts2);
break;
}
document.getElementById("fruit").value=nim;
}
我今晚一定给你修整好!
JavaScript进阶篇
468190 学习 · 21891 问题
相似问题