0

我正在使用 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

在此处输入图像描述

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

在此处输入图像描述

<optgroup class="op1" label="kerala">是缺失的。知道怎么做吗?

4

1 回答 1

-2

看起来它有未关闭的 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>
于 2013-10-29T09:59:35.360 回答