Posted in Javascript onJanuary 10, 2014
js遍历页面控件,
var inputArr = document.forms[0]; for( var i = 0; i < inputArr.length; i++ ) { if( inputArr[i].type.toUpperCase() == "BUTTON" ) { inputArr[i].disabled="disabled"; }else if( inputArr[i].type.toUpperCase() == "FILE" ){ inputArr[i].readonly=true; } }
另一种方法:
var Elements = document.getElementsByTagName_r("*"); var msgs; var i; for ( i in Elements ) { if ( Elements[i].type == "text" ) { alert(Elements[i].value); } }
JS遍历控件取值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>JS遍历控件取值</title> <mce:script type="text/javascript"><!-- function Submit() { var Text=document.getElementsByTagName("input"); var Array=""; for(var i=0;i<Text.length;i++) { if(Text[i].type=="text"||Text[i].type=="checkbox") { Array+=","; Array+=Text[i].value; } } Array=Array.substring(1,Array.length); alert(Array); } // --></mce:script> </head> <body> <table> <tr> <td style="width: 100px"> <input id="Checkbox1" type="checkbox" value="胡果" />胡果</td> <td style="width: 100px"> <input id="Text1" type="text" value="ws_hgo" /></td> <td style="width: 100px"> <input id="Button1" type="button" value="button" onclick="Submit(this)" /></td> </tr> </table> </body> </html>
遍历页面 text控制代码
function Texts() { //var els= document.getElementsByTagName("*"); //els得到页面所有控件 var els= document.getElementsByTagName("INPUT"); //上面的也可,这样可以减少循环 var msgs=""; for (var i=0;i<els.length;i++ ) { if (els[i].type == "text" ) { //取得控件ID msgs += els[i].id + ","; } } alert(msgs); }
javascript遍历控件实例详细解析
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@