如何将这个SimpleModal变为onLoad?

时间:2010-08-06 07:13:10

标签: javascript jquery modalpopups

如何在加载页面时加载此SimpleModal脚本而不是单击按钮?谢谢=)

< div id ='basic-modal'>

<a href='#' class='basic'>Demo</a>
</div>

        &LT; div id =“basic-modal-content”&gt;             

基本模态对话

            

对于此演示,SimpleModal正在使用此“隐藏”数据作为其内容。您还可以使用标准HTML或DOM元素填充模式对话框。

            

示例:

            

$('#basicModalContent').modal(); // jQuery object; this demo

            

$.modal(document.getElementById('basicModalContent')); // DOM

            

$.modal('<p><b>HTML</b> elements</p>'); // HTML

    </div>




    <!-- preload the images -->
    <div style='display:none'>
        <img src='img/basic/x.png' alt='' />
    </div>
</div>

2 个答案:

答案 0 :(得分:2)

jQuery提供.ready()处理程序,该处理程序在加载浏览器DOM content时触发。

$(document).ready(function(){
    // code which executes on dom ready
});

这是

的捷径
$(function(){
});

还有其他几种方式/处理程序。您还可以处理window onload事件,如果所有内容都是完整加载的(图像,iframe等),则会触发该事件。

window.onload = function(){
     alert('onload! yay!');
};

jQuery'ish

$(window).load(function(){
    alert('onload! yay!');
});

答案 1 :(得分:0)

只需将您的代码放在窗口的load事件上,如下所示:

$(window).load(function(){
  $('#basicModalContent').modal();
});