选择标签中的选项可以携带多个值吗? [英] Can an Option in a Select tag carry multiple values?

查看:100
本文介绍了选择标签中的选项可以携带多个值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML表单中选择了一些选项:
(数据将被收集并使用PHP进行处理)

测试:

 < SELECT NAME =测试> 
< OPTION VALUE =1> One
< OPTION VALUE =2>两个

一个选项可能带有多个值,例如用户选择
One ,那么与此选项相关的其他一些值将写入数据库。



我应该如何设计 SELECT Tag,以便每个选项都可以携带一个以上的值,如下所示:

 < SELECT NAME =Testing > 
< OPTION VALUE =1value =2010> One


解决方案

第二个对象:

 < select name => 
< option value ={'num_sequence':[0,1,2,3]}>选项一< / option>
< option value ={'foo':'bar','one':'two'}> Option two< / option>
< / select>

编辑(回答后3年)将两个值都放入JSON格式(使用 JSON.stringify()),因为我抱怨说我的概念验证答案可能会混淆新手开发者。

I got a select tag with some options in a HTML form:
(the data will be collected and processed using PHP)

Testing:

<SELECT NAME="Testing">  
  <OPTION VALUE="1"> One  
  <OPTION VALUE="2"> Two  
  <OPTION VALUE="3"> Three
</SELECT>

Is it possible for an option to carry multiple values like when a user selects "One", then a few other values related to this option will be written to the Database.

How should I design the SELECT Tag so that each of the options can carry one than one value like this:

<SELECT NAME="Testing">  
  <OPTION VALUE="1" value="2010"> One  
  <OPTION VALUE="2" value="2122"> Two  
  <OPTION VALUE="3" value="0"> Three
</SELECT>

解决方案

One way to do this, first one an array, 2nd an object:

    <select name="">
        <option value="{'num_sequence':[0,1,2,3]}">Option one</option>
        <option value="{'foo':'bar','one':'two'}">Option two</option>
    </select>

Edited (3 years after answering) to put both values into JSON format (using JSON.stringify()) because of a complaint that my proof-of-concept answer "could confuse a newbie developer."

这篇关于选择标签中的选项可以携带多个值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆