這個代碼為啥不靈呢,好奇怪,是哪錯了,望高手指導,謝謝!
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?var x=document.getElementById("txt1").value;
? ? ? ?var y=document.getElementById("txt2").value;
? ?var sel=document.getElementById("select").value;
var fur=0;
switch(sel)
{case"+";
? ?fur=parseInt(x)+parseInt(y);
? ?break;
? ?case"-";
? ?fur=parseInt(x)-parseInt(y);
? ?break;
? ?case="*";
? ?fur=parseInt(x)*parseInt(y);
? ?break;
? ?case="/";
? ?fur=parseInt(x)/parseInt(y);
? ?break;
}
? ? ? document.getElementById("fruit").value =fur;??
? ?}
? ?
? </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>
2020-07-18
兄die,你這個改改哈
把標點改成:
把不必要的等號去掉
應該就pass了
2020-07-20
多謝指點,謝謝