這段運算代碼哪里錯了?
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>?
? <script type="text/javascript">
?? function count(){
???? var t1 = document.getElementById("txt1").value;
???? var t2 =document.getElementById("txt2").value;
???? var sel = document.getElementById("select").value;
???? var sum;
???? switch(sel){
???? case "+":sum = parseInt(t1)+parseInt(t2);break;
???? case "-":sum = parseInt(t1)-parseInt(t2);break;
???? case "*":sum = parseInt(t1)*parseInt(t2);break;
???? case "/":sum = parseInt(t1)/parseInt(t2);break;
???? }
???? document.getElementById("fruit").value = sum;???
?? }
? </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=' = ' /> <!--通過 = 按鈕來調用創(chuàng)建的函數(shù),得到結果-->
?? <input type='text' id='fruit' />??
?</body>
2016-06-07
等號這個按鈕沒有調用上面創(chuàng)建的函數(shù),等號的input里面加上?onClick="count()" ?這樣就可以了
2016-06-02
函數(shù)沒有被調用,在按鈕處加上onclick="";
2016-06-02
沒有通過=按鈕來調用創(chuàng)建的函數(shù),函數(shù)沒有調用成功哦!