如何在加载页面时加载此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>
答案 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();
});