Fancybox 不是一个函数

发布于 2024-09-28 20:06:49 字数 1395 浏览 4 评论 0原文

您好,当有人在文本框中输入地址并点击旁边的提交按钮时,我正在使用 jQuery 插件 fancybox 来显示 bing 地图。然后加载一个 fancybox 并显示该地址的地图。这在我的应用程序中运行良好,但问题是,它仅在一个页面上运行良好,而在另一页面上运行良好,当我加载它时,它给我一个错误,说 fancybox 不是函数。我在错误控制台和萤火虫控制台中看到此错误。我不确定会出现什么问题。相同的代码在另一个页面上可以工作,但在这个页面上却不起作用?

$("<a href=\"#showmap\">Map</a>").fancybox is not a function

我很确定这不是可重用性问题。但是当我测试fancybox的原始文件是否已加载时,它们是通过dom加载的,所以这可能不是实际问题。但我无法理解还有什么问题。

这是我的代码

缩写:只是一个文本位。根据用户选择的内容,我有不同的 div。每个 div 都有自己的控件,这些控件以该文本开头,并附加自己的定义,例如 mapresults、decValLat、decValLon 等。

例如:abbr>>east 然后 id 将是 eastmapresults、eastdecValLat、eastdecValLon 等。

function showMapFancybox(abbr){
    var abbr;
    $('#'+abbr+'mapresults').hide(); 
    $('<a href="#showmap">Map</a>').fancybox({
        overlayShow: true,
        onClosed: function() {
            $('#'+abbr+'mapresults').show();
            map_latdec = $('#decValLat').attr('value');
            map_longdec = $('#decValLon').attr('value');
            map_latdeg = $('#degValLat').attr('value');
            map_longdeg = $('#degValLon').attr('value');

            $('#'+abbr+'decValLatsub').val(map_latdec);
            $('#'+abbr+'decValLonsub').val(map_longdec);
            $('#'+abbr+'degValLatsub').val(map_latdeg+'N');
            $('#'+abbr+'degValLonsub').val(map_longdeg+'W');
        }
    }).click();    
};

Hello I am using the jQuery plugin fancybox to display bing maps when somebody enters an address into a textbox and hits the submit button beside it. And a fancybox is loaded and a map for that address is displayed. This is working well with my application, but the problem is, it is only working well on one page and on the other one, when I load it, it is giving me an error saying fancybox is not a function. I get to see this error in the error console and in the firebug console. I am not sure what could the problem. The same code works in another page, but it doesn't on this one?

$("<a href=\"#showmap\">Map</a>").fancybox is not a function

I am pretty sure it is not re-usability issue. But when I test to see if fancybox's original files have been loaded, they are loaded with the dom, so it might not be actual problem. But I am unable to understand what else could the problem be.

This is my code

abbr: is just a text bit. I have different divs based on what the user selects. And each div would have its own controls, which would start with that text and are appended with their own definitions such as mapresults, decValLat, decValLon etc.

ex: abbr>>east
and then the ids would be eastmapresults, eastdecValLat, eastdecValLon etc.

function showMapFancybox(abbr){
    var abbr;
    $('#'+abbr+'mapresults').hide(); 
    $('<a href="#showmap">Map</a>').fancybox({
        overlayShow: true,
        onClosed: function() {
            $('#'+abbr+'mapresults').show();
            map_latdec = $('#decValLat').attr('value');
            map_longdec = $('#decValLon').attr('value');
            map_latdeg = $('#degValLat').attr('value');
            map_longdeg = $('#degValLon').attr('value');

            $('#'+abbr+'decValLatsub').val(map_latdec);
            $('#'+abbr+'decValLonsub').val(map_longdec);
            $('#'+abbr+'degValLatsub').val(map_latdeg+'N');
            $('#'+abbr+'degValLonsub').val(map_longdeg+'W');
        }
    }).click();    
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

凉城凉梦凉人心 2024-10-05 20:06:49

我已经遇到了这种类型的错误,因为我在插件导入后重新加载 jQuery,检查你是否错误地重新导入了 jquery(有时包含在像 jQuery 工具这样的包中)。

I already had this type of errors because i was reloading jQuery after the plugin import, check you don't reimport jquery by mistake (sometimes included in a package like jQuery tools).

卷耳 2024-10-05 20:06:49

我刚刚遇到了这个问题,似乎某些版本的 jQuery 与 FancyBox 的版本不兼容,例如 Fancybox 1.3.4 在低于 1.7 的 jQuery 版本中存在错误,并且不适用于高于 1.8 的版本。

I just had this issue, it seem some versions of jQuery are not compatible with versions of FancyBox, for example Fancybox 1.3.4 is buggy with jQuery versions below 1.7 and doesn't work on version higher than 1.8.

二智少女 2024-10-05 20:06:49

可能的解决方案:

1)你已经加载了jQuery吗?如果没有,则在任何 $ 命令启动之前加载它。

2) 检查一下,您可能在页面中多次加载 jquery 库 (.js)。尝试只加载一个。

3)在文件末尾,您可以执行以下javascript命令:$ = jQuery.noConflict();,它可能会解决。如果没有,那么在任何地方使用单词 jQuery 而不是 $,它也会起作用。

Possible Solutions:

1) have you already loaded jQuery? If not, then load it before any $ commands start.

2) Check, probably you are loading jquery library (.js) several times during the page. Try to load only one.

3) In the end of file, you can execute this javascript command: $ = jQuery.noConflict(); and it might solve. If not, then anywhere use the word jQuery instead of $, and it will work too.

姜生凉生 2024-10-05 20:06:49

您需要在主 fancybox 插件之前加载 easing.js 和 mousewheel.js 等扩展。这样就解决了问题。

You need to load the extensions like easing.js and mousewheel.js BEFORE the main fancybox plugin. That solves the problem.

舞袖。长 2024-10-05 20:06:49

如果“fancybox”作为函数不存在,则可能是 jQuery 源或插件源无法加载到您的页面中。确保路径、文件名和扩展名均正确。

编辑: 在链接到任何插件之前,请确保链接到 jQuery 源。如果插件在 jQuery 之前加载到 HTML 中,则该插件会失败。

If "fancybox" as a function does not exist, it is likely that either the jQuery source or the plugin source are failing to load into your page. Make sure that the pathing, file names, and extension are all correct.

EDIT: Make sure that you link to jQuery Source before you link to any plugins. If a plugin is loaded into your HTML before jQuery is, the plugin fails.

很快妥协 2024-10-05 20:06:49

就我而言,它是 jQuery.noConflict();排在另一个 jQuery 插件中...当我删除所有内容后开始工作。

In my case it was jQuery.noConflict(); row in another jQuery plugin ... when I removed everything started to work.

薔薇婲 2024-10-05 20:06:49

如果您使用的插件在标头标记中包含 JQuery,则可能会出现此问题。
我最近在我的博客中添加了“TheThe Slider”,我所有的 FancyBox 都停止工作了。不过,对于这种情况有一些简单的解决办法。基本上,转到插件目录,搜索对 jquery 的调用并使其有条件使用。如果您想查看我的实现,我关于它的博客< /a> 带有屏幕捕获。

If you are using a plugin which includes JQuery into your header tag, this trouble can arise.
I recently added 'TheThe Slider' to my blog, all my FancyBoxes stopped working. There are easy fixes for this situation though. basically, go to the plugin directory, search for the call to jquery and make it's usage conditional. If you would like to see my implementation of this I did blog about it with screen-capture.

丢了幸福的猪 2024-10-05 20:06:49

我在我的 WordPress 网站上遇到了这个问题,我发现这个问题的发生是由于我安装的两个插件的代码中出现了两次 fancybox.js 。因此,请检查您的代码并确保从一个源加载。

I got this issue in my WordPress web site and I found the issue was happening due to fancybox.js presenting twice in the code from two plugins which I installed. So check your code and make sure to load from one source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文