【问题标题】:Jquery select2 is not working for multiple 'optgroup'Jquery select2 不适用于多个“optgroup”
【发布时间】:2013-10-29 09:45:06
【问题描述】:

我正在使用 Jquery select2,我有一个这样的选择框

<select multiple="multiple" id="address">
    <optgroup class="op1" label="Maryland">
        <optgroup class="op2" label="Perth">
            <option value="West Baltimore Street, Baltimore, MD">West Baltimore Street, Baltimore, MD</option>
            <option value="Massachusetts">Massachusetts</option>
            <option value="Njurunda, Sweden">Njurunda, Sweden</option>
        </optgroup>
    </optgroup>

    <optgroup class="op1" label="Kerala">
        <optgroup class="op2" label="Ernakulam">
            <option value="Ernakulam, Kerala, India">Ernakulam, Kerala, India</option>
            <option value="Muvattupuzha, Kerala, India">Muvattupuzha, Kerala, India</option>
        </optgroup>
        <optgroup class="op2" label="Idukki">
            <option value="Thodupuzha, Kerala, India">Thodupuzha, Kerala, India</option>
        </optgroup>
    </optgroup>
</select>

select2 得到的输出

而我的实际输出应该是这样的

&lt;optgroup class="op1" label="kerala"&gt; 缺失。 知道怎么做吗?

【问题讨论】:

  • 使用单级 optgroup 嵌套。

标签: jquery jquery-select2


【解决方案1】:

看起来它有未关闭的 html 标签,请验证您的 html。经过验证的标记如下所示

<select multiple="multiple" id="address">
    <optgroup class="op1" label="Maryland"></optgroup>
    <optgroup class="op2" label="Perth"></optgroup>
    <option value="West Baltimore Street, Baltimore, MD">West Baltimore Street, Baltimore, MD</option>
    <option value="Massachusetts">Massachusetts</option>
    <option value="Njurunda, Sweden">Njurunda, Sweden</option>
    <optgroup class="op1" label="Kerala"></optgroup>
    <optgroup class="op2" label="Ernakulam"></optgroup>
    <option value="Ernakulam, Kerala, India">Ernakulam, Kerala, India</option>
    <option value="Muvattupuzha, Kerala, India">Muvattupuzha, Kerala, India</option>
    <optgroup class="op2" label="Idukki"></optgroup>
    <option value="Thodupuzha, Kerala, India">Thodupuzha, Kerala, India</option>
</select>

【讨论】:

  • optgroup 应该包含选项列表。此外,根据HTML 5 std,不需要结束标签。
猜你喜欢
  • 2019-12-18
  • 2014-11-14
  • 2013-04-14
  • 2015-01-09
  • 1970-01-01
  • 2020-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多