幫看下是哪里出錯了,得不出結果
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var a=document.get.ElementById("txt1").value; ?
? ? var b=document.get.ElementById("txt2").value; ?
? ? var c=document.get.ElementById("select").value;
? ? var n = parseFloat(a);
? ? var j = parseFloat(b);
? ? var r;
? ? switch(c){
? ? ? ? case "+":r=n+j;break;
? ? ? ? case "-":r=n-j;break;
? ? ? ? case "*":r=n*j;break;
? ? ? ? case "/":r=n/j;break;
? ? }
? ? document.getElementById("fruit").value=r;
? ? //獲取第一個輸入框的值
//獲取第二個輸入框的值
//獲取選擇框的值
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ? //設置結果輸入框的值?
? ??
? ?}
? </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>
為什么不行了,看不出哪里出錯了,求高手指教
2016-02-22
?var a=document.get.ElementById("txt1").value; ?
? ? var b=document.get.ElementById("txt2").value; ?
? ? var c=document.get.ElementById("select").value;
這三行代碼出錯了,應該是document.getElementById,get和ElementById中間沒有點。
2016-02-22
function count(){
? ? var a=document.get.ElementById("txt1").value; ?
? ? var b=document.get.ElementById("txt2").value; ?
? ? var c=document.get.ElementById("select").value;
這里應該是document.getElementById
而不是 document.get.ElementById
你多了一個 .
2016-02-22
根據我的測試,是引號的問題,設置以及使用ID的時候不要一會用單引號一會用雙引號。(具體我也不是太清楚),另外單引號最好是在雙引號內才使用,以此來區分引號內又有引號的情況,因為程序讀取語言是從左到右讀的這樣“”“”程序無法讀懂你的引號是開始的還是結束的,所以要這樣“‘‘“。