標籤:http 代碼 下拉框 元素 htm button 分享 nload inpu
1.點擊下拉框選擇資訊
2.點擊按鈕,下拉框內選擇的資訊會自動跳轉到文本輸入框
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>無標題文檔</title> 6 7 <script> 8 /* 9 HTML 的屬性操作:讀、寫10 屬性名稱:11 屬性值:12 13 讀操作:擷取、找到14 元素.屬性名稱15 16 寫操作:“添加?”、替換、修改17 元素.屬性名稱 = 新的值18 19 */20 window.onload = function (){21 var oBtn = document.getElementById(‘btn1‘);22 var oText = document.getElementById(‘text1‘);23 var oSelect = document.getElementById(‘select1‘);24 25 oBtn.onclick = function (){26 //oBtn.value = ‘button‘;27 //oText.value = 123;28 oText.value = oSelect.value;29 };30 };31 </script>32 33 </head>34 35 <body>36 37 <input id="text1" type="text" />38 <select id="select1">39 <option value="北京">北京</option>40 <option value="上海">上海</option>41 <option value="杭州">杭州</option>42 </select>43 <input id="btn1" type="button" value="按鈕" />44 45 </body>46 </html>範例程式碼:
JS的屬性操作(2)