简体   繁体   English

更改 jQuery 弹出窗口以显示在页面加载中

[英]Change jQuery popup to appear on page load

I am trying to create a jQuery popup that will appear automatically when a webpage loads.我正在尝试创建一个 jQuery 弹出窗口,该弹出窗口将在网页加载时自动出现。 Here is a working code for a popup which opens up with click on a button that I am using:这是一个弹出窗口的工作代码,单击我正在使用的按钮打开它:

$('[data-popup-close]').on('click', function(e)  {
    var targeted_popup_class = jQuery(this).attr('data-popup-close');
    $('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);

    e.preventDefault();
});

How do I write the code if I want the popup above to appear as specified?如果我希望上面的弹出窗口按指定显示,我该如何编写代码? In this format if it's possible please:如果可能,请采用这种格式:

$('[data-popup-close]').on('page-load', function(e)  {

If you want the popup as soon as the page is ready, you simply pass the function to be executed to the JQuery object .如果您希望在页面准备好后立即弹出,您只需将要执行的函数传递给 JQuery 对象 There is no need for binding with on .不需要与on绑定。 Keep in mind that now that the function is invoked by a different object, this will be bound to window and not the data-popup-close element.请记住,现在该函数由不同的对象调用, this将绑定到window而不是data-popup-close元素。

$(function(e)  {
    var targeted_popup_class = $('[data-popup-close]').attr('data-popup-close');
    $('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM