我要取得页面上所有文本域的对象如:
var text = document.getElementById(文本域的id);但是页面上的文本域太多了,我不能都用id去取有没有人知道怎么取?
var text = document.getElementById(文本域的id);但是页面上的文本域太多了,我不能都用id去取有没有人知道怎么取?
解决方案 »
- 关于如何获取ifamge中的html 控件image的onclick事件?急。在线等,马上给分
- JS创建Script节点的问题
- 页面弹出气泡提示
- 在firefox里用document.write输出html代码为什么不行?
- _____________________一个小问题_______________________
- 求助~js网页另存为时能不能指定保存格式
- 请教,日期比较.
- 如何用JavaScript获取上一个页面的URL?
- 一个有关mediaplayer的问题,在先给分
- 如图 我用的是windows的gitbash,现在卡在如何切换选项了
- js中怎么截取中文字符串呀.
- 如何将一个文件转换成EXCEL
这两个都是返回数组var 变量 = window.document.getElementsByName('对象的name')
var 变量 = window.document.forms['表单名']for( var i = 0; i < 变量.length; i++)
{
变量[i].value
}
var files=new Array();
for(var i=0;i<inputs.length;i++)
{
if (inputs[i].type=="file")
files[files.length]=inputs[i].value;
}
function getAllText(){
var obj=document.getElementsByTagName("input");
var txtobjs=new Array();//存放所有的text对象
for (var i=0;i<obj.length;i++){
if (obj[i].type=="text") txtobjs[txtobjs.length]=obj[i]
}
return txtobjs;
}
window.onload=function(){
var tobj=getAllText();
alert("当前页面共有:"+tobj.length+"个")}
</script>
改成
if (inputs[i].type=="text")
function getInputText(){
var arrInput=document.getElementsByTagName('input');//遍历所有input
var arrText=new Array();
for(i=0;i<arrInput.length;i++){
if(arrInput[i].type.toLowerCase()=="text")
alert(arrInput[i].name);//提示type为text的input对象的name
arrText[arrText.length]=arrInput[i];//取出type为text的input对象存入新的数组
}
}
</script>a1:<input type="text" name="a1" value="" size="30"><br>
bb:<input type="radio" name="bb" value="1">aaa
<input type="radio" name="bb" value="2">bbb<br>
cc:<input type="password" name="cc" value="" size="30"><br>
a2:<input type="" name="a2" value="" size="30"><br>
ff:<input type="checkbox" name="ff" value="">1111111
<input type="checkbox" name="ff" value="">222222222<br>
a3:<input name="a3" value="" size="30"><br>
zz:<input type="button" name="zz" value="test" onclick="getInputText();">凡以下形式的均可以取到:
<input type="text" name="">
<input type="" name="">
<input name="">