隐藏div并且不再显示它

时间:2015-09-14 12:16:59

标签: javascript toggle onmouseover

我有这个代码在“onmouseover”时显示和隐藏两个div。

   function hide_visibility(id) {
       var e = document.getElementById(id);
       if (e.style.display == 'none') e.style.display = 'block';
       else e.style.display = 'none';
   }

我想要的是:当我执行鼠标悬停时,它会永久隐藏div,当我再次移动时它将不再显示。

http://codepen.io/anon/pen/XmXjmx

谢谢!

2 个答案:

答案 0 :(得分:4)

您只需删除将e.style.display设置为block的任何代码。

function hide_visibility(id) {
   var e = document.getElementById(id);
   e.style.display = 'none';
}

http://codepen.io/anon/pen/ojbzbK

答案 1 :(得分:1)

您可以将html代码设置为空白,如下所示:

$(document).ready(function() {

    $( "#item" ).mouseover(function() {
        $( "#item" ).html(""); //Set html contents of #item to empty
    });

});

当然,由于您删除了html代码,因此无法再取消隐藏此内容。但是,如果不再需要使元素可见,则无关紧要。