如果我们单击页面上的任何位置,气泡应该关闭

Bubble should close if we click any where on the page

本文关键字:气泡 位置 任何 单击 我们 如果      更新时间:2023-09-26
    $(document).ready(function() {
$('#username_input').live("focus", function() {
             $('.user-available-info').hide();
             $('.user-available-error').hide();
             $('.login-error').hide();
     });
    $('#password_input').live("focus", function() {
             $('.login-error').hide();
             $( '#login-username-invalid').hide();
             $( '#login-username-error').hide();
         });
    This is the xhtml page
    <h:panelGroup id="login-username-invalid" >
    <div id="login-username-invalid-error">     
                <div class="login-error">
                    <div class="login-error-top"></div>
                    <div class="login-error-middle">
    <p class="error">
    "message to be displayed in the bubble"</P>

我们在应用程序中有一个登录页面,如果用户输入无效的用户名或密码,则会弹出错误气泡。我们有一个要求,如果用户单击页面上的任何位置,气泡应该关闭。它适用于用户名和密码输入字段,因为我给出了上面代码中列出的 .hide。但是我尝试将输入字段 ID 更改为"body",以使其在整个页面上工作。但它从未奏效。我尝试了 .click 和 .bind 它们都不起作用。有没有解决方案 为它。提前谢谢。

绑定到单击正文,而不是焦点:http://jsfiddle.net/brentmn/QDjSV/1/

$('body').on('focus', function(){
    alert('body does not recieve focus');
});
$('body').on('click', function(){
    alert('body does recieve click');
});