Html 使用隐藏输入字段传递多个值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3073001/
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-29 03:31:11  来源:igfitidea点击:

Passing multiple values with hidden input fields

htmlinputhidden-field

提问by David

With a select tag, it is possible to post multiple values using only HTML by selecting more than one option?

使用 select 标签,是否可以通过选择多个选项仅使用 HTML 发布多个值?

For example:

例如:

<select multiple="" >
    <option value="1"/>
    <option value="2"/>
    <option value="3"/>
</select>

Is it possible to pass more than one value as one would achieve with the previous example using one or more <input type="hidden">fields? Again, strictly with HTML.

是否可以像使用一个或多个<input type="hidden">字段的前一个示例那样传递多个值?再次,严格使用 HTML。

回答by Victor Stanciu

Use [ ] in the field name to send multiple values:

在字段名称中使用 [ ] 发送多个值:

<input type="hidden" name="your_field_name[]" value="1" />
<input type="hidden" name="your_field_name[]" value="2" />
<input type="hidden" name="your_field_name[]" value="3" />

You will get an array of values in the your_field_name field.

您将在 your_field_name 字段中获得一组值。