【问题标题】:Hide div when page is clicked, unless specific div was clicked单击页面时隐藏 div,除非单击特定 div
【发布时间】:2012-06-07 14:10:23
【问题描述】:

当用户点击topic_tag_sug 或其任何子元素时,该 div 不应隐藏。但是当用户点击任何其他元素时,topic_tag_sug 应该隐藏。

HTML

<input id='topic_tag' onblur="$('#topic_tag_sug').hide();"/>
<div id='topic_tag_sug' style='border:1px solid #000'>here is tag suggestion zone, i want to click here to select tag suggestion, and it will not be hide</div>​

JavaScript

$('#topic_tag').focus();

http://jsfiddle.net/Q7hFw/2/

【问题讨论】:

  • 你想做什么?你的问题不是很清楚。
  • 很抱歉,您能更清楚地说明您要达到的目标吗?
  • 嗯,将“onblur”改为“onclick”?
  • 当我们点击 topic_tag_sug 时我想要。 topic_tag_sug 不会隐藏。
  • 我很困惑??????如果您不希望它隐藏,请取出onblur="$('#topic_tag_sug').hide();" 或者您是否尝试在用户单击未触发 onblur 事件的 topic_tag_sug 时实现这一点?

标签: javascript jquery html onblur


【解决方案1】:

您想在其他事件中隐藏建议框,这很有趣。让我们在框内添加一个关闭按钮,

<input id='topic_tag' />
<div id='topic_tag_sug' style='border:1px solid #000;display:none;'>
    here is tag suggestion zone, i want to click here to select tag suggestion, and it will not be hide
    <br>
    <a id="close" href="#">X: Close</a>
</div>

现在使用 jQuery 添加一些 javaScript 代码

$(document).ready(function() {
    $('#topic_tag').bind('click', function() {
        $('#topic_tag_sug').show();  
    });    
    $('#close').bind('click', function() {
        $('#topic_tag_sug').hide();
    });        
});

请找到工作示例here

【讨论】:

    猜你喜欢
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    相关资源
    最近更新 更多