我没有从 jshint 或控制台收到此代码的错误。然而,我的 ajax 内容并没有发布到预期的 div 中。但是,警报会触发:
var recentVar;
var highlightsVar;
var test3;
var test4;
function switcher(divToShow, thisVar, otherVar, url, div){
$("#site-nav li a").parents().removeClass("nav-active");
$(div).addClass("nav-active");
if (otherVar){ $(otherVar).detach();}
if(typeof thisVar === 'undefined') {
thisVar = $(divToShow + " ul.top-level").load("assets/includes/" + url, function () {
alert("I'm new");
});
} else {
$(thisVar).appendTo("#content-listing");
alert("I'm old");
}
}
//Recent
$("#site-nav .nav1").on("click", function (event) {
switcher("#recent", "recentVar", "highlightsVar", "recent.php", "#site-nav .nav1");
event.preventDefault();
});
//Highlights
$("#site-nav .nav2").on("click", function (event) {
switcher("#highlights", "highlightsVar", "recentVar", "all-web.php", "#site-nav .nav2");
event.preventDefault();
});