我试图在单击链接后显示#subscribe-pop div,并在单击链接之外的任何位置时隐藏它。如果我更改以下内容,我可以让它显示和隐藏:
$('document').click(function() {
至
$('#SomeOtherRandomDiv').click(function() {
HTML:
<div id="footleft">
<a href="#" onclick="toggle_visibility('subscribe-pop');">Click here to show div</a>
<div id="subscribe-pop"><p>my content</p></div>
</div>
脚本:
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById("subscribe-pop");
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
}
$('document').click(function() {
$('#subscribe-pop').hide(); //Hide the menus if visible
});
$('#subscribe-pop').click(function(e){
e.stopPropagation();
});
</script>