2011-02-15 47 views
8

我想根据病情来选择文本字段,例如:选择输入字段名作为数组字段

if only text field name = sname[] than only put value in it. 

为此,我使用

<input type="text" name="sname[]" /> 

where name = sname; 

//For each name type field in extra add contact module if that i visible. 
    $('input[name=' + name + '[]]').each(function() { 

}); 

但我不能进入它的内部。请建议如何进入选择。

回答

16
$('input[name="' + name + '[]"]').each(function() { 
    $(this).val('Some value'); 
}); 
+0

jsFiddle:http://jsfiddle.net/M2Jnx/ – stealthyninja 2011-02-15 06:08:10

2

无需每次循环,你可以做到这一点,如:

$('input[name="field_name[]"]').val('Some value'); 

希望这有助于。