【发布时间】:2011-07-04 15:02:29
【问题描述】:
我使用了两个 2 jquery(插件)脚本,一个用于导航,一个用于动态内容。
- http://www.i-marco.nl/weblog/jquery-accordion-3/
- http://css-tricks.com/dynamic-page-replacing-content/
他们单独工作很好,但不能一起工作。我厌倦了切换脚本,当我更改 index.html 中脚本的顺序时,最后一个脚本开始工作,就像它忽略了第一个脚本一样。例如,按此顺序,菜单正在工作:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.ba-hashchange.min.js" type="text/javascript"></script>
<script src="js/dynamicpage.js" type="text/javascript"></script>
<script src="js/menu.js" type="text/javascript"></script>
按照这个顺序,动态内容正在工作:
<script src="js/menu.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.ba-hashchange.min.js" type="text/javascript"></script>
<script src="js/dynamicpage.js" type="text/javascript"></script>
这是动态页面.js:
$(function() {
var newHash = "",
$mainContent = $("#main-content"),
$pageWrap = $("#wrapper"),
baseHeight = 0,
$el;
$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();
$("nav").delegate("a", "click", function() {
window.location.hash = $(this).attr("href");
return false;
});
$(window).bind('hashchange', function(){
newHash = window.location.hash.substring(1);
if (newHash) {
$mainContent
.find("#guts")
.fadeOut(200, function() {
$mainContent.hide().load(newHash + " #guts", function() {
$mainContent.fadeIn(200, function() {
$pageWrap.animate({
height: baseHeight + $mainContent.height() + "px"
});
});
$("nav a").removeClass("current");
$("nav a[href="+newHash+"]").addClass("current");
});
});
};
});
$(window).trigger('hashchange');
})(jQuery);
这是 menu.js :
jQuery.fn.initMenu = function() {
return this.each(function(){
var theMenu = $(this).get(0);
$('.acitem', this).hide();
$('li.expand > .acitem', this).show();
$('li.expand > .acitem', this).prev().addClass('active');
$('li a', this).click(
function(e) {
e.stopImmediatePropagation();
var theElement = $(this).next();
var parent = this.parentNode.parentNode;
if($(parent).hasClass('noaccordion')) {
if(theElement[0] === undefined) {
window.location.href = this.href;
}
$(theElement).slideToggle('normal', function() {
if ($(this).is(':visible')) {
$(this).prev().addClass('active');
}
else {
$(this).prev().removeClass('active');
}
});
return false;
}
else {
if(theElement.hasClass('acitem') && theElement.is(':visible')) {
if($(parent).hasClass('collapsible')) {
$('.acitem:visible', parent).first().slideUp('normal',
function() {
$(this).prev().removeClass('active');
}
);
return false;
}
return false;
}
if(theElement.hasClass('acitem') && !theElement.is(':visible')) {
$('.acitem:visible', parent).first().slideUp('normal', function() {
$(this).prev().removeClass('active');
});
theElement.slideDown('normal', function() {
$(this).prev().addClass('active');
});
return false;
}
}
}
);
});
};
$(document).ready(function() {$('.menu').initMenu();});
请帮忙,我会很感激的!
附:这是当前脚本的顺序,其中只有动态内容有效,菜单无效:
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/menu.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.ba-hashchange.min.js" type="text/javascript"></script>
<script src="js/dynamicpage.js" type="text/javascript"></script>
【问题讨论】:
-
尝试联系他们的开发人员,也许他们以前已经遇到过这个问题。很难判断一个人是否不了解插件的完整代码或从未遇到过与您相同的情况。
标签: jquery scripting dynamic conflict