大家來找茬啦
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?alert("test");
? ? ? ?var x=document.getElementById('txt1').value;
? ? ? ?var y=document.getElementById('txt2').value;
? ? //獲取第一個輸入框的值
//獲取第二個輸入框的值
? ?var z=document.getElementById('select').value;
? ?var o;
//獲取選擇框的值
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
switch(z){
? ? case:"+"
? ? return o=x+y;
? ? break;
? ??
}
? ? //設置結果輸入框的值?
? ? ? ?document.getElementById("fruit").value=o;
? ?}
? </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>
2019-01-18
switch(z){
? ? case "+":
? ? o=parseFloat(x)+parseFloat(y);
}
2019-01-03
2019-01-02
lll
2019-01-02
2019-01-02
改為 o = x+y;不需要return