劍斂卿塵
2015-11-04 13:05:51
<!DOCTYPE?html>
<html>
?<head>
??<title>?事件</title>??
??<script?type="text/javascript">
???function?count(){
???????var?one=parseInt(document.getElementById("txt1").value);
???????var?two=parseInt(document.getElementById("txt2").value);
???????var?san=parseInt(document.getElementById("select").value);
???????var?num="?";
???????while?(san)?{
???????????case?=?"+":
???????????num?=?one?+?two;
???????????break;
???????????vase?=?"-":
???????????num?=?one?-two;
???????????break;
???????????case?="*":
???????????num?=?one?*?two;
???????????break;
???????????case?="/":
???????????num?=?one?/?two;
???????????break;
???????}
???????
???????document.getElementById("fruit").value=num;
???}
??</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()"?/>?<!--通過?=?按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
???<input?type='text'?id='fruit'?/>???
?</body>
</html>
4 回答
已采納

李曉健
TA貢獻1036條經(jīng)驗 獲得超461個贊
switch(n) { case?1: ??執(zhí)行代碼塊?1 ??break; case?2: ??執(zhí)行代碼塊?2 ??break; default: ??n?與?case?1?和?case?2?不同時執(zhí)行的代碼 }
switch ? case ?語法是這樣的,不知道你是怎么改的。

慕勒2844754
TA貢獻1條經(jīng)驗 獲得超0個贊
你的代碼:
?while?(san)?{????????????????//while 應(yīng)該是switch
???????????case?=?"+":
???????????num?=?one?+?two;
???????????break;
? ? vase?=?"-":????????????//vase ?是 case吧
???????????num?=?one?-two;
???????????break;
???????????case?="*":
???????????num?=?one?*?two;
???????????break;
???????????case?="/":
???????????num?=?one?/?two;
???????????break;
???????}
????????
添加回答
舉報
0/150
提交
取消