【问题标题】:Select2 dropdown not shown properly in UI with struts tags带有 struts 标签的 UI 中未正确显示 Select2 下拉列表
【发布时间】:2020-12-24 18:14:10
【问题描述】:

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

以下是代码:

//这里包含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 被包含在控制台中,没有任何错误。但输出不如预期。

请注意:HTML 页面中有多个表单。某些表单使用普通下拉菜单而不是 Select2。请帮我解决这个问题。提前致谢!

【问题讨论】:

    标签: javascript jquery dropdown jquery-select2


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 2016-01-28
      • 2016-02-14
      • 2020-07-17
      相关资源
      最近更新 更多