2013-01-22 203 views
0

我有一个简单的函数,插入一个动画的“工作”图像,然后显示“完成!” POST完成后。但是,我希望这一次发生在多个地方。jquery stop元素隐藏点击

实施例在:http://veretekk.com/developer/temp/

的更多细节在页面上面概述,但基本上当包含该按钮在其内部被点击#dialog元件被隐藏。另外... jquery使用.on而不是$(document).ready(function() {的原因是,这个内容可以在DOM加载后出现在我的网站上,因此需要随时可用。帮帮我!

+0

我的猜测是,'$( “member_button_friend _” +用户).html'移除事件目标,导致'if($(“#dialog”)。is(“:visible”)...'检查失败,而不是使用'.html',隐藏输入并使用'.append' –

+0

我没有正确地得到你的问题......当我点击忽略按钮时没有任何反应,没有图像按钮改变完成..但没有其他更改页面上...... – Scorpio

+0

我的第一个建议是通过删除内联JavaScript来解开代码。内联JavaScript更难以维护和调试。 on('click','.ignorebutton',function(){})'',而不是'onclick = FriendAction(“USER”)'',只需使用$('#dialog')。在函数内部,您可以从对话框中获取用户ID(数据元素或元素ID等)。 –

回答

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/

+0

优秀 - 谢谢!使用这个和更多的调整我应该能够到达那里... –