jquery 覆盖不会在本地主机上触发
我正在尝试整理本地测试环境,并成功设置 xampp 来提供 php 页面。这是我第一次这样做,所以很可能我会犯新手错误!
但是,我知道 javascript 是客户端,因此 jquery 由 localhost 提供服务这一事实应该不会有任何区别?
我有一个带有 jquery 覆盖层的页面,它可以完美地在线工作 - 即由远程服务器提供服务。但是,当我加载通过 xampp 本地提供的页面时,firebug 显示以下错误:
$("#modifile_link[rel]").overlay is not a function
[Break On This Error] onBeforeLoad: function() {
这是 jquery 调用...
$(function() {
// Setup a basic iframe for use inside overlays.
var theframe = $('<iframe class="iframe_style" frameBorder="0" scrolling="no"></iframe>');
// Overlay
$("#modifile_link[rel]").overlay({effect: 'apple',
mask: {
color: '#000000',
loadSpeed: 1000,
opacity: 0.6
},
closeOnClick: false,
onBeforeLoad: function() {
// grab wrapper element inside content
var wrap = this.getOverlay().find(".contentWrap");
//Get the URL from the trigger
var link = this.getTrigger().attr("href");
// load the page specified in the trigger
$(theframe).attr({ src: link });
//Write the iframe into the wrap
wrap.html(theframe);
}
});
});
绑定到此链接...
<div id="modifile_link" href="scripts/modifile/index.php" rel="#overlay_1"></div>
这是覆盖层的 html...
<div class="overlay_1" id="overlay_1">
<div class="overlay_content">
<div class="contentWrap"></div>
</div><!-- end overlay content -->
</div><!--end overlays html-->
所以,这看起来很奇怪在 firebug 中,正在加载 jquery 文件,但 onBeforeLoad: function() 不被接受。没有进行ajax,所以我想排除跨域安全限制?我不知道。
任何指点都会很棒。
谢谢。
斯科特
I'm trying to get a local testing environment sorted out and have successfully set up xampp to serve php pages. This is the first time I've done this so it's very possible I'm making newbie errors!
However, I'm aware that javascript is clientside so the fact the jquery is being served by localhost shouldn't make any difference?
I have a page with a jquery overlay and which works perfectly online - i.e., served by remote server. However, when I load the page locally served via xampp, firebug show me the following error:
$("#modifile_link[rel]").overlay is not a function
[Break On This Error] onBeforeLoad: function() {
Here's the jquery call...
$(function() {
// Setup a basic iframe for use inside overlays.
var theframe = $('<iframe class="iframe_style" frameBorder="0" scrolling="no"></iframe>');
// Overlay
$("#modifile_link[rel]").overlay({effect: 'apple',
mask: {
color: '#000000',
loadSpeed: 1000,
opacity: 0.6
},
closeOnClick: false,
onBeforeLoad: function() {
// grab wrapper element inside content
var wrap = this.getOverlay().find(".contentWrap");
//Get the URL from the trigger
var link = this.getTrigger().attr("href");
// load the page specified in the trigger
$(theframe).attr({ src: link });
//Write the iframe into the wrap
wrap.html(theframe);
}
});
});
which is bound to this link...
<div id="modifile_link" href="scripts/modifile/index.php" rel="#overlay_1"></div>
and here's the html for the overlay...
<div class="overlay_1" id="overlay_1">
<div class="overlay_content">
<div class="contentWrap"></div>
</div><!-- end overlay content -->
</div><!--end overlays html-->
SO, it's seems strange that in firebug the jquery file is being loaded but the onBeforeLoad: function() is not being accepted. There's no ajax going on so I thought to rule out a cross domain security restriction? I don't know.
Any pointers would be great.
Thanks.
Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保您的文件存在于本地服务器上并且路径正确。右键单击浏览器中的页面,“查看页面源代码”,然后单击 JavaScript 链接以查看它们是否打开或服务器是否返回 404 未找到。
如果您无法从浏览器访问 javascript 文件,请首先检查它们是否存在于本地文件夹结构中,但我的猜测是您的 url 是错误的。注意绝对/相对路径。尝试包含带有相对 url 的 javascript 文件
(开头没有
/
)You need to make sure your files exist on the local server and that the paths are correct. Right click the page from your browser, "view page source", and click on the javascript links to see if they open or server returns 404 not found.
If you can't access the javascript files from the browser, first check if they are even present in the local folder structure, but my guess is that your url's are wrong. Pay attention to absolute/relative paths. Try including your javascript files with a relative url
(without a
/
in the beginning)