如何使用javascript获取没有id和名称字段的输入框的值 [英] how to get value of input box without id and name field using javascript

查看:1580
本文介绍了如何使用javascript获取没有id和名称字段的输入框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有3个输入框的表单,所有的输入框都没有id,name字段。所以如果我输入值,如何检查输入框的值没有id和名称字段使用javascript

 < form id ='a'action =''> 
< input type ='text'value =''/>
< input type ='text'value =''/>
< / form>

这是html中的代码,我想要使用javascript输入框的值。我可以这样做吗?

解决方案

您可以获得对他们的引用并检查他们的 property。



为了支持更新的浏览器......

  []。forEach.call(document.querySelectorAll(#a input [type ='text']),
function(input){
var value = input.value;
});

如果您需要支持仍然萦绕不定的烦人浏览器,只需编写更多代码并(b)
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ var $ input $ document.getElementById(a)。getElementsByTagName(input);
var i;
var length;
var value;

for(i = 0,length = inputs.length; i //检查我们有[type ='text']
if(输入[i] .type!=text){
continue;
}
value = inputs [i] .value;

}


I have a form with 3 input box and all the input box does not have id, name field in it. So if i enter value in it, How can i check the value of input box without id and name field using javascript

<form id='a' action='' >
    <input type='text' value='' />
    <input type='text' value='' />
</form>

This is the code in html and i want to have the value of input box using javascript. Can i do that?

解决方案

You could get a reference to them and check their value property.

For the luxury of supporting newer browsers...

[].forEach.call(document.querySelectorAll("#a input[type='text']"),
               function(input) {
                   var value = input.value;
               }); 

If you need to support the annoying browsers that still seem to linger, just write a bit more code and you're good as gold.

var inputs = document.getElementById("a").getElementsByTagName("input");
var i;
var length;
var value;

for (i = 0, length = inputs.length; i < length; i++) {
     // Check we have [type='text']
     if (inputs[i].type != "text") {
         continue;
     }
     value = inputs[i].value;

}

这篇关于如何使用javascript获取没有id和名称字段的输入框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆