【发布时间】:2021-05-12 15:35:06
【问题描述】:
我们正在通过列表填充下拉列表中的选项。这些值被添加到 Action 类的列表中。 当 option 等于某个特定值时,我们想隐藏它。
以下是代码:
if (stuval.substring(0, 7) == "<option") {
$('#stuclass option:not(:first)').remove();
$('#stuclass').find('option').end().append($(stuval));
}
当值为“不适用”时如何隐藏选项?
我们正在使用 select2 插件。尝试在 CSS 中使用以下代码。
.select2-results [data-select2-id*="not apply"]{
display : none;
}
此代码的问题是它正在从页面中的所有下拉列表中删除“不应用”选项。要求是如何申请该下拉列表(使用 id)。选项应该被隐藏但不被移除或禁用。请帮助
HTML 代码:
<tr>
<td><b><bean:message
key="label.stuclass" />:</b></td>
<td><html:select property="stuclass" style="text-transform: uppercase;background-color: #A5A5A5;"
styleId="stuclass">
<html:option value=""><bean:message key="label.stuclass.select" /></html:option>
<html:optionsCollection name="studentForm" property="stuList" label="label" value="value" />
</html:select></td>
</tr>
While Jquery loading :
$("#stuclass").select2({ width: '150px'});
将“不适用”作为其选项之一的其他下拉菜单:(通过操作类将值加载到后端的此下拉菜单中)
$("#stuStatusSearch").select2({ width: '150px'});
<html:select property="stuStatusSearch" styleId="stuStatusSearch">
<html:option value=""><bean:message key="label.stuStatusSearch.select" />
</html:option><html:optionsCollection name="studentForm" property="stuStatusList" label="label" value="value" />
</html:select>
【问题讨论】:
-
显示更多代码。
-
已编辑问题。我在后端看到的下拉选项。必须根据下拉值隐藏该特定值的要求。请帮忙。
标签: jquery jquery-select2