2010-05-20 82 views
1

我對jquery或javascript沒有經驗。 我正試圖實施這種技術,以迴應用戶的一般錯誤或消息。Jquery背景覆蓋/警報沒有.onclick事件 - PHP響應者?

lights-out-dimmingcovering-background-content-with-jquery

此方法使用onclick事件這不是什麼即時通訊後,我試圖與.load更換.onclick但似乎並沒有工作。我經過一個快速修復,因爲我真的沒有時間學習jQuery或它的事件處理程序。

目標是捕獲任何錯誤或消息,並且一旦調用這些命令,就會調用警報框,而不會執行任何其他操作,如.onclick。

如何我的代碼看起來:

{PHP} 
$forms = new forms(); 
if(count($forms->showErrors) > 0 // or == true) 
{ 
    foreach($forms->showErrors as $error) 
    { 
     print('<p class="alert">'.htmlspecialchars($error, ENT_QUOTES).'</p>'); 
    } 
} 

編輯: 所有固定,謝謝!

回答

2

你在「.load」的正確軌道上,但是你想把這個功能綁定到頁面的「ready」事件上(當DOM完成時,你不需要等待load事件),所以這裏就是你需要改變 - 假設你正在使用的熄燈頁面上的代碼示例:

$(document).ready(function(){ 

    //Adjust height of overlay to fill screen when page loads 
    $("#fuzz").css("height", $(document).height()); 

    //When the link that triggers the message is clicked fade in overlay/msgbox 
    //$(".alert").click(function(){ 
    // $("#fuzz").fadeIn(); 
    // return false; 
    //}); 

    // INSTEAD: If any errors are present in the page, fade in the layer: 
    if ($("p.alert").length) { 
     $("#fuzz").fadeIn(); 
    } 
    // end of change 

    //When the message box is closed, fade out 
    $(".close").click(function(){ 
     $("#fuzz").fadeOut(); 
     return false; 
    }); 

}); 

//Adjust height of overlay to fill screen when browser gets resized 
$(window).bind("resize", function(){ 
    $("#fuzz").css("height", $(window).height()); 
}); 

一定要包括圖層的HTML和CSS,太。

+0

非常感謝大衛, 我會盡快嘗試一下,歡呼! – Philip 2010-05-20 01:18:14