2014-12-05 13 views
1

我试图从三个输入文本框中获得价值。但我希望这三个值在一次或数组form.I如何得到? 这里是我的HTML的我怎样才能从三个输入文本框在jQuery时间获得价值

<input style='display:none' value='http://localhost/JSG/upload/Hydrangeas6.jpg' class='imgstr' name='imgstr[]'type='text> 
    <input style='display:none' value='http://localhost/JSG/upload/Jellyfish4.jpg' class='imgstr' name='imgstr[]'type='text'> 
    <input style='display:none' value='http://localhost/JSG/upload/Koala1.jpg' class='imgstr' name='imgstr[]'type='text'> 

jquery-

var images = $('.imgstr').val(); //Get value from text 

回答

4

您可以使用.map()

var images = $('.imgstr').map(function() { 
    return this.value; 
}).get(); 
+0

感谢阿伦先生。 – Secure 2014-12-05 12:52:18

3

你可以mapget它。

var images = $('.imgstr').map(function(){ return this.value }).get(); 
0
$(".imgstr").each(function(index) { 
    console.log($(this).val()); 
}); 
0

做到这一点:

for(var i = 0;i < document.getElementByClassName('imgstr').length;i++){ 

    var images += document.getElementByClassName('imgstr')[i]; 

} 
+0

你不需要.value – Billy 2014-12-05 12:52:20

0

使用jQuery每个迭代上使用您的类属性的所有文本框3。

var combinedValue=null; 

$(".imgstr").each(function(){ 
combinedValue=combinedValue+$(this).val(); 
}); 
1
var results = []; 

$('input.imgstr').each(function() { 
    var thisVal = $(this).val(); 
    results.push(thisVal); 
}); 
相关问题