Javascript 选择on change可在另一个选项中填充特定选项选择not work on safari
这个例子在chrome、firefox上运行良好。。。但不是在旅行中Javascript 选择on change可在另一个选项中填充特定选项选择not work on safari,javascript,safari,hide,show,Javascript,Safari,Hide,Show,这个例子在chrome、firefox上运行良好。。。但不是在旅行中 $("#select1").change(function() { var id = $(this).val(); $("#select2 option").each(function() { if ($(this).val() == id) { $(this).show(); } else { var arrVal = $(this).val().split(',');
$("#select1").change(function() {
var id = $(this).val();
$("#select2 option").each(function() {
if ($(this).val() == id) {
$(this).show();
} else {
var arrVal = $(this).val().split(',');
if(arrVal.indexOf(id)>-1)
$(this).show();
else
$(this).hide();
}
});
});
工作示例:
你知道怎么解决吗?TIA因为在某些浏览器中不能隐藏
元素。您可以使用
将其包装以隐藏:
$('#select1').change(function() {
var id = $(this).val();
$('#select2 option').each(function() {
var arrVal = $(this).val().split(',');
if ($.inArray(id, arrVal) > -1) {
if ($(this).parent('span').length)
$(this).unwrap();
} else {
if ($(this).parent('select').length)
$(this).wrap('<span>');
}
});
});
$('#select1')。更改(函数(){
var id=$(this.val();
$(“#选择2选项”)。每个(函数(){
var arrVal=$(this.val().split(',');
如果($.inArray(id,arrVal)>-1){
if($(this.parent('span').length)
$(this.unwrap();
}否则{
if($(this).parent('select').length)
$(此).wrap(“”);
}
});
});
在操作中看到这一点:有没有办法让select2“Select Item”中的第一个选项始终显示出来?例如