没有.onclick事件的jQuery背景覆盖/警报-PHP响应器? [英] Jquery background overlay/alert without .onclick event - php responder?
问题描述
对于此事,我没有使用jquery或javascript的经验. 我正在尝试实施这种技术以响应用户的错误或消息.
I have no experience with jquery or javascript for that matter. I am trying to implement this technique to respond to users for errors or messages in general.
lights-out-dimmingcovering-background-带有jQuery的内容
此方法使用onclick事件,这不是即时消息,我尝试将.onclick替换为.load,但这似乎不起作用.我正在快速解决问题,因为我真的没有时间学习jquery或其事件处理程序.
This method uses the onclick event and that's not what im after, I have tried to replace .onclick with .load but that doesn't seem to work. I'm after a quick fix as I really don't have the time to learn jquery or its event handlers.
目标是捕获任何错误或消息,并在调用这些错误或消息后立即调用警报框,而无需执行任何其他操作,例如.onclick.
The goal is to catch any errors or message's and once these are called the alert box is called without any further actions such as .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>');
}
}
全部修复,谢谢!
推荐答案
您使用".load"处于正确的轨道,但是您希望将此功能绑定到页面的"ready"事件(当DOM为完成;您无需等待load事件),因此需要进行以下更改-假设您正在使用Lights Out页面上的代码示例:
You're on the right track with ".load" but you want to bind this functionality to the "ready" event of the page (when the DOM is complete; you don't need to wait for the load event), so here's what you need to change - assuming you're using the code sample on the Lights Out page:
$(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.
Be sure to include the HTML and CSS for the layer, too.
这篇关于没有.onclick事件的jQuery背景覆盖/警报-PHP响应器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!