我appaently具有帶我在一個頁面jQuery的聲明一個問題:錯誤使用jQuery宣言
http://www.northernvirginiapaintingcontractor.com點擊「畫圖事實」
錯誤:$ .fn'爲空或不對象
指該行:
$.fn.accordion = function() {
我使用這個聲明另一個網站,並能正常工作。
但是,對於這個網站,這不行。
在網站上的一個單獨的頁面:GeneralContact jQuery的宣言建立這樣的:
jQuery(document).ready(function ($) {
我沒有足夠的經驗,jQuery的調試這一點,如果有人能看出問題,我會很感激!
看來,這個腳本在幾個地方引用$: moredetail_click() hidedetail_click() according_set()
我不知道是否有一個變通的所有「$的「引用,或者如果我應該重寫這個?
$.fn.accordion = function() {
return this.each(function() {
$container = $('#FactsLeftColumn');
$container.find("dt").each(function() {
var $header = $(this);
var $selected = $header.next();
$header.click(function() {
$('.active').removeClass('active');
$(this).addClass('active');
if ($selected.is(":visible")) {
$selected.animate({
height: 0
}, {
duration: 300,
complete: function() {
$(this).hide();
var id = $(this).attr("id");
var num;
if (id.length < 3) {
num = id;
} else {
num = id.substring(2, id.length);
}
$('#hidden_' + num).hide();
$('#more' + num).show();
}
});
} else {
$unselected = $container.find("dd:visible");
$selected.show();
var newHeight = heights[$selected.attr("id")];
var oldHeight = heights[$unselected.attr("id")];
$('<div>').animate({
height: 1
}, {
duration: 300,
step: function (now) {
var stepSelectedHeight = Math.round(newHeight * now);
$selected.height(stepSelectedHeight);
$unselected.height(oldHeight + Math.round((newHeight - oldHeight) * now) - Math.round(newHeight * now));
if ($unselected.attr("id") != null) {
var id = $unselected.attr("id");
var num;
if (id.length < 3) {
num = id;
} else {
num = id.substring(2, id.length);
}
$('#hidden_' + num).hide();
$('#more' + num).show();
}
},
complete: function() {
$unselected.hide().css({
height: 0
});
}
});
}
return false;
});
});
var heights = new Object();
$container.find("dd").each(function() {
$this = $(this);
$this.css("overflow", "hidden");
heights[$this.attr("id")] = $this.height();
$this.hide().css({
height: 0
});
});
});
};
function moredetail_click(ddnum) {
$('#view_' + ddnum).hide();
$('#hidden_' + ddnum).show();
var newHeight = $('#hidden_' + ddnum).height() + 2;
if (ddnum < 5) {
$('#' + ddnum).height(newHeight);
} else {
$('#Dd' + ddnum).height(newHeight);
}
}
function hidedetail_click(ddnum) {
$('#hidden_' + ddnum).hide();
$('#view_' + ddnum).show();
var newHeight = $('#view_' + ddnum).height() + 1;
if (ddnum < 5) {
$('#' + ddnum).height(newHeight);
} else {
$('#Dd' + ddnum).height(newHeight);
}
}
function according_set() {
$("#FactsLeftColumn").accordion();
}
$(document).ready(function() {
$("#featured > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 5000, true);
var idnum = 1;
var ddnum = 1;
$.getJSON('FaqsJson.ashx?factType=1', function (datas) {
var str_one = "";
str_one = "<dl>"
var array_len = datas.length;
var each_num = 1;
var answer = "";
var split_str;
var len, i, start_pos;
$.each(datas, function() {
if (this['Answer'].length > 200) {
split_str = this['Answer'].split(". ");
len = split_str.length;
answer = "<div id='view_" + ddnum + "'>";
if (split_str[0].length < 150) {
answer += split_str[0] + ". " + split_str[1] + ". <a href='javascript:;' id='more" + ddnum + "' onclick='moredetail_click(" + ddnum + ")' class='moredetail'>Read More</a>";
start_pos = 2;
}
else {
answer += split_str[0] + ". <a href='javascript:;' id='more" + ddnum + "' class='moredetail' onclick='moredetail_click(" + ddnum + ")'>Read More</a>";
start_pos = 1;
}
answer += "</div>";
answer += "<div id='hidden_" + ddnum + "' style='display:none;width:534px;'>";
answer += this['Answer'];
answer += " <a href='javascript:;' id='more" + ddnum + "' class='moredetail' onclick='hidedetail_click(" + ddnum + ")'>Read Less</a>";
answer += "</div>";
}
else {
answer = this['Answer'];
}
str_one += "<dt class=\"glossquestion\"><a href=\"javascript://\" class=\"questionLink\">" + this['Question'] + "</a></dt>";
if (idnum < 5)
str_one += "<dd id=\"" + ddnum + "\" class=\"glossanswer\" style=\"right-margin:5px;width:544px;\"><div class=\"answerbox\" style=\"width:536px;\">" + answer + "</div></dd>";
else
str_one += "<dd id=\"Dd" + ddnum + "\" class=\"glossanswer\" style=\"right-margin:5px;width:544px;\"><div class=\"answerbox\" style=\"width:536px;\">" + answer + "</div></dd>";
idnum++;
ddnum++;
each_num++;
str_one += "</dl>";
});
$("#glossary_first").html(str_one);
window.setTimeout(according_set, 2000);
});
});
是否正確引用了jQuery?你是否試圖引用兩個正在接管的版本?另一個框架竊取'$'選擇器?需要關於你的設置更多的信息 – Taz 2013-02-14 00:44:30
我相信是的 - 另一個框架竊取'$'選擇器,我有不同的GeneralContact頁面(我在問題中引用)的jQuery聲明設置,但我不清楚如何將'fn.accordian'部分融入其中。 – Paul 2013-02-14 00:45:59