[英]How to suppress JavaScript function with eg. hasClass?
I'm building on a WordPress theme and wants to load posts and pages with AJAX. 我以WordPress主题为基础,并希望使用AJAX加载帖子和页面。 I got that sorted out through the snippet below, but now I just need to suppress the function when clicking on the logo, obviously linking to the home url.
我是通过下面的代码片段整理出来的,但是现在我只需要在单击徽标(显然是链接到主网址)时隐藏该功能即可。 So when clicking on the logo it should force a normal reload, instead of using the function.
因此,单击徽标时,应强制正常重新加载,而不是使用该功能。
I figure it would have something to do with "if hasClass(logo) then use default"... Yeah, I'm fairly new to JavaScript, but I have been searching a lot, so any help in the right direction will be much appreciated. 我认为这与“如果hasClass(logo)然后使用默认值”有关……是的,我对JavaScript还是很陌生,但是我一直在搜索很多东西,因此在正确方向上的任何帮助都会很多赞赏。 Thanks!
谢谢!
The snippet: 片段:
$(".home li.home").removeClass("home").addClass("current_page_item"); var $wrapperAjax = $("#wrapper-ajax"), URL = '', siteURL = "http://" + top.location.host.toString(), $internalLinks = $("a[href^='"+siteURL+"']"), hash = window.location.hash, $ajaxSpinner = $("#ajax-loader"), $el, $allLinks = $("a"); function hashizeLinks() { $("a[href^='"+siteURL+"']").each(function() { $el = $(this); if ($.browser.msie) { $el.attr("href", "#/" + this.pathname) .attr("rel", "internal"); } else { $el.attr("href", "#" + this.pathname) .attr("rel", "internal"); } }); }; hashizeLinks(); $("a[rel='internal']").live("click", function() { $ajaxSpinner.fadeIn(); $wrapperAjax.animate({ opacity: "0.1" }); $el = $(this); $(".current_page_item").removeClass("current_page_item"); $allLinks.removeClass("current_link"); URL = $el.attr("href").substring(1); URL = URL + " .entry"; $wrapperAjax.load(URL, function() { $el.addClass("current_link").parent().addClass("current_page_item"); $ajaxSpinner.fadeOut(); $wrapperAjax.animate({ opacity: "1" }); hashizeLinks(); }); }); $("#searchform").submit(function(e) { $ajaxSpinner.fadeIn(); $wrapperAjax.animate({ opacity: "0.1" }); $el = $(this); $(".current_page_item").removeClass("current_page_item"); $allLinks.removeClass("current_link"); URL = "/?s=" + $("#s").val() + " .entry"; $wrapperAjax.load(URL, function() { $ajaxSpinner.fadeOut(); $wrapperAjax.animate({ opacity: "1" }); hashizeLinks(); }); e.preventDefault(); }); if ((hash) && (hash != "#/")) { $("a[href*='"+hash+"']").trigger("click"); }
If it has the class .logo
you could add this at the top of the function: 如果它具有类
.logo
,则可以将其添加到函数顶部:
if ($(this).hasClass('logo')) return true;
See the simple example . 参见简单示例 。
I'm guessing you mean the script from this line: $("a[rel='internal']")
我猜你是说这行的脚本:
$("a[rel='internal']")
In that case, $("a[rel='internal']").not('.logo')
should do the trick. 在这种情况下,
$("a[rel='internal']").not('.logo')
应该可以解决问题。
I should've read the entire code. 我应该阅读完整的代码。 Replace
$("a[href^='"+siteURL+"']")
with $("a[href^='"+siteURL+"']").not('.logo')
as well. 也将
$("a[href^='"+siteURL+"']")
替换$("a[href^='"+siteURL+"']").not('.logo')
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.