弄了一晚上,就是不知道哪兒有問題。
求解答。。。
<!DOCTYPE html>
<html>
?<head>
? <title>事件—計算器</title> ?
? <script type="text/javascript">
? ?function count(){
? ? //獲取第一個輸入框的值
? ? var i=parseInt(document.getElementById("txt1").value);
? ? //獲取第二個輸入框的值
? ? var j=parseInt(document.getElementById("txt2").value);
//獲取選擇框的值
? ? var k=document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ? var res=document.getElementById("fruit");
? ? //設置結果輸入框的值?
? ? switch(k)
? ? {
? ? ? ? case "+":
? ? ? ? ? ? res.value=i+j;
? ? ? ? ? ? break;
? ? ? ? case "-":
? ? ? ? ? ? res.value=i-j;
? ? ? ? ? ? break;
? ? ? ? case "*":
? ? ? ? ? ? res.value=i*j;
? ? ? ? ? ? break;
? ? ? ? case "/":
? ? ? ? ? ? if(j!=0)
? ? ? ? ? ? ? ? res.value=i/j;
? ? ? ? ? ? else
? ? ? ? ? ? ? ? res.value="非法輸入!";
? ? ? ? break;
? ?}
}
? </script>?
?</head>?
?<body>
? ?<input type='text' id='txt1' />?
? ?<select id='select'>
<option value='+' selected="selected">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
? ?</select>
? ?<input type='text' id='txt2' />?
? ?<input type='button' value=' = ' oncliclk="count()"/> <!--通過 = 按鈕來調用創建的函數,得到結果-->?
? ?<input type='text' id='fruit';value="" /> ??
?</body>
</html>
2014-11-19
onclick事件寫錯了,你寫成oncliclk了。。。