課程
/前端開發
/JavaScript
/JavaScript進階篇
javascript進階6-11編程的程序???
2017-01-09
源自:JavaScript進階篇 6-11
正在回答
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var v1 = parseInt(document.getElementById('txt1').value); ??
? ? //獲取第一個輸入框的值
? ? var v2 = parseInt(document.getElementById('txt2').value);
//獲取第二個輸入框的值
? ? var fuhao = document.getElementById('select').value;
? ? var result= '';
//獲取選擇框的值
? ? switch(fuhao)
? ? {
? ? ? ? case '+': result = v1+v2;break;
? ? ? ? case '-': result = v1-v2;break;
? ? ? ? case '*': result = v1*v2;break;
? ? ? ? case '/': result = v1/v2;break;
? ? ? ??
? ? }
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ? //document.write("shuchu");
? ? //window.alert(shuchu);
? ? //return shuchu;
? ? //設置結果輸入框的值?
? ? document.getElementById('fruit').value=result;
? ?}
? </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>
慕仔7135344 提問者
舉報
本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界
2 回答Javascript進階篇6-11的編程練習
4 回答javascript進階篇6-10編程練習
1 回答JavaScript進階編程實戰
2 回答javaScript進階篇5-6 編程練習 幫我改錯
4 回答javaScript進階篇4-10編程練習
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-01-09
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var v1 = parseInt(document.getElementById('txt1').value); ??
? ? //獲取第一個輸入框的值
? ? var v2 = parseInt(document.getElementById('txt2').value);
//獲取第二個輸入框的值
? ? var fuhao = document.getElementById('select').value;
? ? var result= '';
//獲取選擇框的值
? ? switch(fuhao)
? ? {
? ? ? ? case '+': result = v1+v2;break;
? ? ? ? case '-': result = v1-v2;break;
? ? ? ? case '*': result = v1*v2;break;
? ? ? ? case '/': result = v1/v2;break;
? ? ? ??
? ? }
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ? //document.write("shuchu");
? ? //window.alert(shuchu);
? ? //return shuchu;
? ? //設置結果輸入框的值?
? ? document.getElementById('fruit').value=result;
? ?}
? </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>