选择后是否可以将多个值存储在选项标签中?在 Laravel

Is It possible to store multiple values store in the option tag after selection? in Laravel

我的问题是我显示了所有属性下拉列表,在这里我们在 select 之后的 value="{{$play->id}}" 中获取属性 ID 并存储到 select name="attribute_id" 并获取属性 id 很容易,但是我们想存储 selected 的特定属性的 attribute id + attribute unit 之类的 $play->unit,是否有可能在选项 selected 或任何之后获得多个值解决此问题的替代方法?

我的代码是这样的

<select class="form-control" name="attribute_id" id="attribute_id">

     @foreach($plays as $play)

     <option class="form-control" value="{{$play->id}}" >{{$play->attribute}}</option>

     @endforeach

</select>

将值设置为:

<option class="form-control" value="{{$play->id}}**{{$play->unit}}" >{{$play->attribute}}</option>

提交后您将同时获得这两个值。 你需要像这样爆炸():

$attribute = $_POST['attribute'];
$values = explode("**", $attribute);
echo $values[0];  //will contain id
echo $values[1];  // will contain unit

我使用“**”作为分隔符,你可以使用任何东西。