Javascript show/hide will not hide properly in Safari

删除回忆录丶 提交于 2019-12-14 04:09:43

问题


It seems to be a problem with show/hide in Safari. The site looks good freshly loaded. But if you click on the first link up in the left corner and than go back, the show/hide function doesn't work so well anymore and you get layers on top of each other. Note: This problem only occours in Safari.

I've used jQuery and here is my show hide code:

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

Link to site: http://www.smudesign2012.co.uk/


回答1:


I would suggest you use jquery to show/hide the elements.

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();
}



回答2:


try this and note the difference in .style.display

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


来源:https://stackoverflow.com/questions/10504597/javascript-show-hide-will-not-hide-properly-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!