中文字幕亚洲一区,69久久久久精品9999不卡片,亚洲国产日韩欧美在线看片,国产精品久久久久久久久岛国

龍巖易富通網絡科技有限公司

龍巖小程序開發,龍巖分銷系統

常用Javascript表單取值方法

2015.09.10 | 758閱讀 | 0條評論 | 通用代碼

一.常用表單基本取值方法(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);

 }

 }




function clearMateriel(obj)

 {

//全部選中

 if(obj=="all")

 {

 for(var i=0;i<document.getElementById("cblMateriel").getElementsByTagName("input").length;i++)

 {

 document.getElementById("cblMateriel_"+i).checked =true;

 }

 }

//清除

else if(obj=="none")

 {

 for(var i=0;i<document.getElementById("cblMateriel").getElementsByTagName("input").length;i++)

 {

 document.getElementById("cblMateriel_"+i).checked =false;

 }

 }

//反選

 else if(obj=="reverse")

 {

 for(var i=0;i<document.getElementById("cblMateriel").getElementsByTagName("input").length;i++)

 {

 if(document.getElementById("cblMateriel_"+i).checked)

 document.getElementById("cblMateriel_"+i).checked =false;

 else

 document.getElementById("cblMateriel_"+i).checked =true;

 }

 }

 }

本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/yanleigis/archive/2008/11/11/3265656.aspx">http://blog.csdn.net/yanleigis/archive/2008/11/11/3265656.aspx


贊 (

發表評論

主站蜘蛛池模板: 金昌市| 微山县| 怀宁县| 萝北县| 京山县| 东阳市| 井研县| 法库县| 从江县| 呈贡县| 永安市| 什邡市| 双城市| 西华县| 临澧县| 右玉县| 肥乡县| 苏州市| 嘉峪关市| 佛坪县| 郸城县| 汽车| 梅州市| 大余县| 德令哈市| 南城县| 麻阳| 广德县| 石台县| 云阳县| 东乡族自治县| 东丰县| 浮山县| 揭东县| 巴楚县| 建昌县| 疏勒县| 定远县| 南华县| 资溪县| 柞水县|