在Safari中无法正确隐藏JavaScript显示/隐藏

2022-08-22 00:00:00 javascript show-hide

在Safari中显示/隐藏似乎有问题。新加载的网站看起来不错。但如果你点击左上角的第一个链接,然后返回,显示/隐藏功能就不能很好地工作了,你会得到一个又一个层。注意:此问题仅在Safari中出现。

我已经使用了jQuery,下面是我的Show Hide代码:

    <script type="text/javascript">
  function show(id) {
    document.getElementById(id).style.visibility = "visible";
  }
  function hide(id) {
    document.getElementById(id).style.visibility = "hidden";
  }
 </script>

站点链接:http://www.smudesign2012.co.uk/


解决方案

我建议您使用jQuery来显示/隐藏元素。

function show(id){
    $('.student').hide(); // hide all students
    $('#'+id).show(); // show the student with applied ID
}

function hide(id){
    $('#'+id).hide(); // is this needed? Why not do the next one and skip the parameter to the function?
    $('.student').hide();
}

相关文章