久久调教,免费看黄色影片,www五月,国产精品免费一区二区区,亚洲欧美日韩综合一区,亚洲欧美日韩精品在线,2021免费日韩视频网

龍巖易富通網(wǎng)絡(luò)科技有限公司

龍巖小程序開發(fā),龍巖分銷系統(tǒng)

常用Javascript表單取值方法

2015.09.10 | 785閱讀 | 0條評(píng)論 | 通用代碼

一.常用表單基本取值方法(frm為表單名稱,TextBox1為控件ID,以文本框?yàn)槔?html控件與web服務(wù)器控件是一樣的)


 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復(fù)選框(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


實(shí)現(xiàn)功能:遍歷html復(fù)選框,得到所選中項(xiàng)


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


實(shí)現(xiàn)功能:遍歷html復(fù)選框,得到所選中項(xiàng)


代碼同html復(fù)選框


3.html下拉列表框


表單:<select id="Select1" multiple>

 <option value=1>1</option>

 <option value=2>2</option>

 </select>


實(shí)現(xiàn)功能:


 3.1得到所選中項(xiàng)的text和value值(選擇一項(xiàng))


 var selDrp = document.all.Select1;

 alert(selDrp.options[selDrp.selectedIndex].text);

 alert(selDrp.options[selDrp.selectedIndex].value);


 3.2得到所選中項(xiàng)的text和value值(選擇多項(xiàng))


 for(var j=0;j<selDrp.options.length;j++)

 {

 if(selDrp.options[j].selected)

 {

 alert(selDrp.options[j].value);

 }

 }


4.DropDownList控件與ListBox控件


實(shí)現(xiàn)功能:得到所選中項(xiàng)的text和value值


代碼同html下拉列表框


5.CheckBoxList控件


實(shí)現(xiàn)功能:得到所選中項(xiàng)的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;

 }

 }

 }

本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/yanleigis/archive/2008/11/11/3265656.aspx">http://blog.csdn.net/yanleigis/archive/2008/11/11/3265656.aspx


贊 (

發(fā)表評(píng)論