Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择on change可在另一个选项中填充特定选项选择not work on safari_Javascript_Safari_Hide_Show - Fatal编程技术网

Javascript 选择on change可在另一个选项中填充特定选项选择not work on safari

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(',');

这个例子在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(',');
     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”中的第一个选项始终显示出来?例如