I have two dropdownlist. In my initial loading everything gets fine.Based on the first dropdownlist the second dropdownlist works.. my condition is like
我有两个下拉列表。在我的初始加载一切都很好。基于第一个下拉列表第二个下拉列表工作..我的条件是
if(batchType==1||batchType==3){
//here i need to regain values after getting nulled by the else part
}else{
$("#dept").html("");//makes the second dropdownlist null
}
while the else part excecutes,the second dropdownlist becomes null.But after excecuting else part,if the condition will again like "if" part it again shows null.For that i am storing the values inside a variable department.But how to repopulate it from my "if" section...
当else部分超出时,第二个下拉列表变为null。但是在执行else部分之后,如果条件将再次像“if”部分再次显示null。因为我将值存储在变量部门中。但是如何重新填充它来自我的“if”部分......
var department=$('#dept').html();
In my alert i get like
在我的警报中我得到了
<option value="1">CS</option>
<option value="2">Mechanical</option>
<option value="3">Civil</option>
Any help will be highly appreciable
任何帮助都会非常值得一提
1 个解决方案
#1
0
why don't you hide the options rather than clearing them, demo
为什么不隐藏选项而不是清除它们,演示
$( "#dept option" ).val("");
$( "#dept option" ).hide();
<select id="dept">
<option value="0"></option>
<option value="1">CS</option>
<option value="2">Mechanical</option>
<option value="3">Civil</option>
</select>
you can later show the same options by doing
您可以稍后通过执行相同的选项
$( "#dept option" ).show();
#1
0
why don't you hide the options rather than clearing them, demo
为什么不隐藏选项而不是清除它们,演示
$( "#dept option" ).val("");
$( "#dept option" ).hide();
<select id="dept">
<option value="0"></option>
<option value="1">CS</option>
<option value="2">Mechanical</option>
<option value="3">Civil</option>
</select>
you can later show the same options by doing
您可以稍后通过执行相同的选项
$( "#dept option" ).show();