hide()在IE中不起作用 [英] hide() not working in IE
本文介绍了hide()在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码在firefox中运行完美,并在IE中出现错误.有任何想法吗?
My code works perfect in firefox and gives error in IE. any ideas?
我有一个带有各种选项的下拉菜单,我试图根据所选值在另一个下拉菜单中显示/隐藏选项.
I have a dropdown with various options, I am trying to show/hide options in another dropdown based on the selected value.
function selectNames() {
var Name = $("#SelectName").attr("value");
$("."+Name).each(function() {
$(this).hide();
});
}
<select >
<option class="Name1" value="SomeName1" </option>
<option class="Name2" value="SomeName2" </option>
</select>
<select id="SelectName" onchange="javascript:selectNames();" >
<option value="Name1" </option>
<option value="Name2" </option>
</select>
感谢您的帮助.
推荐答案
它在IE&中不起作用铬
It won't work in IE & Chrome
check out in IE or Chrome
您最好的选择是删除选项而不是隐藏它.(在删除选项之前,您应该保留原始选项的副本.)
The best alternative that you can do is to remove the option rather than hiding it.(you should keep a copy of the original options before removing it.)
var copy = $("."+Name).clone();
function selectNames() {
$("#thefirstselect option").remove();
copy.appendTo("#thefirstselect");
var Name = $("#SelectName").val();
$("."+Name).each(function() {
$(this).remove();
});
}
这篇关于hide()在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文