jquery stop元素隐藏在点击上

时间:2013-01-22 20:42:32

标签: jquery

我有一个简单的函数,插入一个动画的“工作”图像,然后显示“完成!” POST完成后。但是,我希望这种情况一次发生在多个地方。

示例:http://veretekk.com/developer/temp/

在上面的页面中概述了更多细节,但基本上#dialog元素在单击其中包含的按钮时隐藏。另外...... jquery使用.on而不是$(document).ready(function() {的原因是,在加载DOM之后,此内容可以出现在我的网站上,因此需要始终可用。救命啊!

1 个答案:

答案 0 :(得分:0)

我认为你的很多问题在于你决定是否隐藏对话框的复杂方式。

不要试图拦截每个文档点击并确定其目标,让jQuery处理细节:

$(document).on('click', function (event) {
    // If the document is clicked, hide the dialog
    $('#dialog').hide();
});

$(document).on('click', '#dialog', function (event) {
    // If the dialog is clicked, stop the propagation
    // of the click event to the document
    // The first handler will never be called
    event.stopPropagation();
});

简化演示:http://jsfiddle.net/jtbowden/M93dZ/