[英]Show modal window on page load
I am aware this question has been asked many times but I just cannot seem to get this to work because of my almost null JS knowledge. 我知道这个问题已经被问过很多次了,但是由于我几乎没有JS知识,我似乎无法使它正常工作。
I am using the Zebra Dialog jquery plugin to make a modal window that I want to open when the page is loaded. 我正在使用Zebra对话框 jquery插件来制作一个模态窗口,该页面在加载页面时要打开。
All the examples on the Zebra Dialog website only explain how to load the modal when clicking a link, but I just cannot seem to get it to load on page load. Zebra对话框网站上的所有示例仅说明了单击链接时如何加载模态,但我似乎无法使其在页面加载时加载。
I am using the following code right now: 我现在正在使用以下代码:
<script type="text/javascript">
$(document).load(function() {
// show a dialog box when clicking on a link
$(anchor).bind('click', function(e) {
e.preventDefault();
$.Zebra_Dialog('The link was clicked!');
});
});
</script>
I am aware that I am using code for loading the modal when clicking on a link but I have tried a lot of stuff and not found a way to succesfully modify it to load on page load. 我知道我在单击链接时使用的是用于加载模式的代码,但是我尝试了很多东西,但没有找到一种成功修改它以在页面加载时加载的方法。
Any help would be greatly appreciated! 任何帮助将不胜感激!
Perhaps jQuery is not included? 也许不包括jQuery? You need jQuery, then the plugin js/css in your <head>
: 您需要jQuery,然后在<head>
使用插件js / css:
<script type="text/javascript" src="path/to/jquery.js"></script>
<script type="text/javascript" src="path/to/zebra_dialog.js"></script>
<link rel="stylesheet" href="path/to/zebra_dialog.css" type="text/css">
and then the the loading code in <body>
(in script tags or loaded from a file) 然后在<body>
加载代码(在脚本标签中或从文件加载)
$(document).ready(function() {
$.Zebra_Dialog('Page loaded!');
});
$(document).load(function() {
$.Zebra_Dialog('The link was clicked!');
});
i would try: 我会尝试:
$(document).ready(function() {
$.Zebra_Dialog('Page loaded!');
});
This basically means that once the document is ready (ie loaded), open your modal dialog. 这基本上意味着,一旦文档准备好(即加载),请打开模式对话框。 Previously you had the code saying, when the document is ready attach a handler to the click event of some element (not sure what 'anchor' is in your code), and in that event handler open the dialog. 以前,您有代码说明,当文档准备就绪时,将处理程序附加到某个元素的click事件(不确定代码中的“锚定”是什么),然后在该事件处理程序中打开对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.