表单下拉选择选项 - 显示文本,在查询字符串中提交ID号

时间:2016-02-14 18:09:38

标签: html forms twitter-bootstrap

在此文档示例中,选项名称是查询字符串中提交的值:http://v4-alpha.getbootstrap.com/components/forms/#form-controls

  <fieldset class="form-group">
    <label for="exampleSelect1">Example select</label>
    <select class="form-control" id="exampleSelect1">
      <option>Example option that can be a really long string</option>
      <option>Another option that can be a duplicate of another string but with a different ID</option>
      <option>Another option that can be a duplicate of another string but with a different ID</option>
    </select>
  </fieldset>

我希望表单具有选项的ID号,而不是这个原始的硬编码,并为用户呈现表示该选项的详细文本:

  <fieldset class="form-group">
    <label for="exampleSelect1">Example select</label>
    <select class="form-control" id="exampleSelect1">
      <option>
        1
        <verbose>Example option that can be a really long string</verbose>
      </option>
      <option>
        2
        <verbose>Another option that can be a duplicate of another string but with a different ID</verbose>
      </option>
      <option>
        3
        <verbose>Another option that can be a duplicate of another string but with a different ID</verbose>
      </option>
    </select>
  </fieldset>

这样,查询字符串将具有ID号,后端不会发生重复短路,并且因为ID已被索引,所以它会更快。

如何实现这一点,<verbose>伪代码标签的正确语法是什么?

1 个答案:

答案 0 :(得分:3)

您正在寻找value标记的<option>属性。例如:

<option value="1">Example option that can be a really long string</option>