一.經常使用表單基本取值方法(frm爲表單名稱,TextBox1爲控件ID,以文本框爲例,html控件與web服務器控件是同樣的) 1.frm.TextBox1.value 2.var txt = document.all.TextBox1; txt.value 3.var txt = document.all["TextBox1"]; txt.value 4.document.getElementById("TextBox1");二.1.html複選框(name相同)表單: <input id="Checkbox1" type="checkbox" name="chk" value="123" />sss <input id="Checkbox2" type="checkbox" name="chk" value="456"/>aaa <input id="Checkbox3" type="checkbox" name="chk" value="789"/>bbb實現功能:遍歷html複選框,獲得所選中項 var oChks = document.all.chk; for(var i=0; i<oChks.length; i++) { if(oChks[i].checked) alert(oChks[i].value); }2.html單選框(name相同)表單: <input id="Radio1" type="radio" name="rad" value="123"/>123 <input id="Radio2" type="radio" name="rad" value="456"/>456實現功能:遍歷html複選框,獲得所選中項代碼同html複選框3.html下拉列表框表單:<select id="Select1" multiple> <option value=1>1</option> <option value=2>2</option> </select>實現功能: 3.1獲得所選中項的text和value值(選擇一項) var selDrp = document.all.Select1; alert(selDrp.options[selDrp.selectedIndex].text); alert(selDrp.options[selDrp.selectedIndex].value); 3.2獲得所選中項的text和value值(選擇多項) for(var j=0;j<selDrp.options.length;j++) { if(selDrp.options[j].selected) { alert(selDrp.options[j].value); } }4.DropDownList控件與ListBox控件實現功能:獲得所選中項的text和value值代碼同html下拉列表框5.CheckBoxList控件實現功能:獲得所選中項的text代碼: var chklist = document.all("CheckBoxList1"); var i = 0; for(i=0;i<chklist.rows.length;i++) { var name = "CheckBoxList1_" + i; var tmpChecked = document.all[name].checked; if(tmpChecked) { alert(document.all[name].parentElement.innerText); } }