在html中显示任一下拉列表
Display either one of the dropdown in html
我正在尝试基于页面的一个uniqueid显示下拉列表。我无法访问html中的uniqueid,所以我将每个下拉列表的单独id隐藏起来,并根据uniqueid的值显示一个下拉列表。
但问题是,即将到来的值有一个逗号(,),这是不需要的。有没有什么方法可以让我在HTML中访问uniqueid的值并显示下拉列表(我不想显示一个并隐藏另一个。)
<select id="x" style="margin-top: 20px">
<c:forEach items="${reporttypes}" var="reporttype">
<option value="${reporttype.reportTypeName}">${reporttype.reportTypeName}</option>
</c:forEach>
</select>
<select id="y" style="margin-top: 20px">
<c:forEach items="${reporttypes}" var="reporttype">
<option value="${reporttype.reportTypeName}">${reporttype.reportTypeName}</option>
</c:forEach>
</select>
if(document.getElementById("abc").value == "TTL"){
$('#x').show();
$('#y').hide();
}
else {
$('#x').hide();
$('#y').show();
}
});
现在我正在尝试这样做,但它不起作用
<select name="typeOption" id="typeOptionIdTTL" class="typeOptionClassTTL" style="margin-top: 20px">
<script>
if(document.getElementById("abc")=="TTL"){
<c:forEach items="${reporttypes}" var="reporttype">
<option value="${reporttype.reportTypeName}">${reporttype.reportTypeName}</option>
</c:forEach>
}
</script>
</select>
现在,而不是用html调用脚本。我正在调用此函数,但仍然无法工作。
function PopulateTypeOption(){
<c:forEach items="${reporttypes}" var="reporttype">
if(document.getElementById("abc")=="TTL"){
select.append($('<option></option>').val(${reporttype.reportTypeName}).html(${reporttype.reportTypeName}));
}
else{
select.append($('<option></option>').val(${reporttype.reportTypeName}).html(${reporttype.reportTypeName}));
}
</c:forEach>
}
用javascript创建一个函数,该函数将在运行时填充选项。调用document.ready中的函数。例如
function Populate(){
if(document.getElementById("abc").value == "TTL" ){
<c:forEach items="${reporttypes}" var="reporttype">
$("#x").append("<option values =${reporttype.reportTypeName}>${reporttype.reportTypeName}</option>");
</c:forEach>
}
else{
<c:forEach items="${reporttypes}" var="reporttype">
$("#abc").append("<option values =${reporttype.reportTypeName}>${reporttype.reportTypeName}</option>");
</c:forEach>
}
}
你不需要两个独立的id x和y。现在只需要一个就足够了。
相关文章:
- 如何使用jQuery选择下拉列表的值
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- Javascript按钮下拉列表
- jQuery表单添加不适用于下拉列表
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 禁用jQuery中的下拉列表
- 如何在按钮中显示下拉列表中选定的元素
- 如何在从多选下拉列表中选择选项值时动态生成文本框
- 如何使用PHP和JS级联三个下拉列表
- 如何在使用剑道 MVVM 下拉列表时强制选择第一项
- 语义ui如何使用javascript启用或禁用下拉列表
- 无法使用PHP动态设置下拉列表中的值
- 如何根据对具有多行的先前列表的选择来动态加载下拉列表
- 下拉列表在使用z索引放置在前面后停止工作
- 从多维嵌套json数组创建下拉列表
- 如何在剑道下拉列表中按文本和值搜索
- 使用下拉列表筛选列表(ul>li)
- 如何使用jquery从下拉列表(javascript)中选择192.168.3.0进行测试自动化
- 使用codeigniter的多链下拉列表
- 在html中显示任一下拉列表