输入 URL 时 Firefox 不加载 jQuery 插件
我在 Firefox 3.6.8 上遇到了一个非常烦人的问题。 我有这个示例插件:
(function($){
$.fn.test_plugin = function(settings){
$(this).load(function(settings){
alert('ok');
});
};
})(jQuery);
在 html 页面的底部,类似这样:
$(function(){
$("#image1").test_plugin();
});
所以基本上,这应该在页面加载后显示一条警报消息,而且确实如此,除非您在 Firefox 上手动输入网址。如果我刷新页面没有问题,但在重定向或手动输入 URL 时却没有问题。我没有收到任何错误,从萤火虫看来一切都很好。这只发生在 FF 上,我在 Safari、chrome、IE 上没有遇到问题。
知道这是为什么吗?
谢谢
I'm having a very annoying issue on Firefox 3.6.8.
I have this sample plugin:
(function($){
$.fn.test_plugin = function(settings){
$(this).load(function(settings){
alert('ok');
});
};
})(jQuery);
And at the bottom of the html page something like this:
$(function(){
$("#image1").test_plugin();
});
So Basically this should show na alert message fter the pages loads, and it does, except, when you type the url manually on Firefox. If I refresh the page no problem, but on redirect or manually typing the URL it's not. I got no errors and from the firebug everything seems to be fine. This only happens on FF, I got no probs on Safari, chrome, IE.
Any idea why this is ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅用于加载的 jQuery API 条目。
要加载的第一个参数是 URL。后面可以选择跟随数据和回调函数。您没有在加载调用中包含 URL。
看起来您正在尝试编写您的第一个 jQuery 插件。如果是这种情况,我建议阅读插件开发模式。
我基于此构建了a Gist,您也可以查看。
See the jQuery API entry for load.
The first argument to load is a URL. This can optionally be followed by data and a callback function. You did not include a URL in your call to load.
It looks like you're trying to write your first jQuery plugin. If that's the case, I'd recommend reading A Plugin Development Pattern.
I built a Gist based on this that you can also look at.
在我看来,您可能尝试使用 jquery 加载函数作为页面卸载事件,这是错误的。 load 函数用于 Ajax 调用,如 calvinf 所说,需要一个 URL 参数以及其他参数才能进行调用。
但多读一些,你就可以很好地编写 jquery 插件了:)
To me it seems that you might have tried to use the jquery load function as a page unload event which is wrong. The load function is for Ajax call which as stated by calvinf requires a URL parameter among other parameters to make the call to.
But read some more and your are well on your way to write jquery plugins :)
好的,谢谢您的回复,不过我似乎已经解决了。
我刚刚使用
它
解决了问题,并且在其他浏览器上运行良好。
Ok, thanks for your replies, however I've seem to fixed it.
I've just used
instead of
It fixed the problem and it's working fine on the other browsers.