jQuery 选择名称为数组字段的输入字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5000368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:21:33 来源:igfitidea点击:
Select input field with name as array field
提问by Jos
I wanted to select the text field based on condition, for example:
我想根据条件选择文本字段,例如:
if only text field name = sname[] than only put value in it.
For this I used
为此,我使用了
<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() {
});
But I'm not able to get inside of it. Please suggest how to get into the selection.
但我无法深入其中。请建议如何进入选择。
回答by stealthyninja
$('input[name="' + name + '[]"]').each(function() {
$(this).val('Some value');
});
回答by Zakaria Acharki
No need for each loop, you could do it like :
不需要每个循环,你可以这样做:
$('input[name="field_name[]"]').val('Some value');
Hope this helps.
希望这可以帮助。