how to get value of input box without id and name field using javascript

后端 未结 5 2055
耶瑟儿~
耶瑟儿~ 2021-01-20 09:35

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 nam

5条回答
  •  长发绾君心
    2021-01-20 10:07

    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;
    
    }
    

提交回复
热议问题