Select2 下拉列表未在带有 struts 标签的 UI 中正确显示

Select2 dropdown not shown properly in UI with struts tags

我的 selec2 下拉菜单显示不正确。

代码如下:

//这里包含select2 CSS文件 HTML代码:

<div>   
                            <tr>
                                <td><b><bean:message key="label.student.display" />:</b>
                                <html:select property="stuCode" styleId="rollno" onchange="getStuData(this);">
                                <html:option value=""><bean:message key="label.student.select" /></html:option>
                                <html:option value="ABC">ABC</html:option>
                                <html:option value="XYZ">XYZ</html:option>
                                <html:optionsCollection name="studentForm" property="StuList"  label="label" value="value" />
                                </html:select>
                                </td>
                                </tr>
                                </div>
//included javascript select2 tag
</body>

JQuery代码:

$(function() {
            $("#rollno").select2();
            
    });

Select2 被包含在 console.But 中没有任何错误,输出不符合预期。

请注意:HTML page.Some 中有多个表单使用普通下拉列表而不是 Select2。请提前帮我解决这个问题issue.Thanks!

给 struts 标签中的 select 一个宽度,它应该可以工作。我以前遇到过同样的问题。我认为这就是问题所在,我没有发现任何其他问题。

您还可以使用select2 的宽度参数并设置宽度。如果您想在 struts 标签中给出百分比宽度,那么在创建 select2 时请执行以下操作

$("#rollno").select2({
    width: 'resolve'
});

当然你也可以使用css来设置html中select的宽度。