為什么運行不來?哪出問題了???(計算器)
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var ys3='';
? ? //獲取第一個輸入框的值
? ?var ys1=document.getElementById("txt1").value;
//獲取第二個輸入框的值
? ?var ys2=document.getElementById("txt2").value;
//獲取選擇框的值
? ?var ys =document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ??
? ? switch(ys){
? ? //設(shè)置結(jié)果輸入框的值
? ? case"+":
? ? ? ? ?ys3=parseInt(ys1)+parseInt(ys2);
? ? ? ? ? ? break; ?
? ? case"-":
? ? ? ? ?ys3=parseInt(ys1)-parseInt(ys2);
? ? ? ? ? ? break;
? ? case"*":
? ? ? ? ?ys3=parseInt(ys1)*parseInt(ys2);
? ? ? ? ? ? break;
? ? default:
? ? ? ? ?ys3=parseInt(ys1)/parseInt(ys2);
? ??
? ?}
? ? ?document.getElementById('ye4').value=ys3;
? ?}
? </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='ye4' /> ??
?</body>
</html>
2016-03-03
第七行的 var ys3='';沒有問題;
主要的錯誤就是line 24:?
line27:
語句后面的冒號是在中文狀態(tài)下的冒號,你把它改成英文狀態(tài)下的冒號就能正常運行
2016-03-03
case"*":和default:后面的冒號你用了中文冒號。。。
2016-03-03
2016-03-03
語法錯誤。var ys3;