問題描述
您好,當有人在文本框中輸入地址并點擊旁邊的提交按鈕時,我正在使用 jQuery 插件 fancybox 來顯示 bing 地圖.并加載了一個fancybox,并顯示了該地址的地圖.這在我的應用程序中運行良好,但問題是,它只在一個頁面上運行良好,而在另一頁上運行良好,當我加載它時,它給我一個錯誤,說 fancybox 不是一個函數.我在錯誤控制臺和螢火蟲控制臺中看到了這個錯誤.我不確定可能是什么問題.相同的代碼可以在另一個頁面上運行,但在這個頁面上不行?
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
我很確定這不是可重用性問題.但是當我測試fancybox的原始文件是否已經加載時,它們是與dom一起加載的,所以它可能不是實際問題.但我無法理解還有什么問題.
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.
這是我的代碼
abbr: 只是一個文本位.根據用戶的選擇,我有不同的 div.每個 div 都有自己的控件,這些控件以該文本開頭,并附加有自己的定義,例如 mapresults、decValLat、decValLon 等.
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.
例如:縮寫>>東然后 id 將是eastmapresults、eastdecValLat、eastdecValLon 等.
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();
};
推薦答案
我已經遇到過這種類型的錯誤,因為我在插件導入后重新加載了 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).
這篇關于Fancybox 不是函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!