简体   繁体   English

如何抑制JavaScript功能与例如。 hasClass?

[英]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.

相关问题 如何使用httpPost()函数从p5.js JavaScript库发布xml数据(例如xml文件)? - How to post xml data(for eg. a xml file) from the p5.js JavaScript library using the httpPost() function? Javascript中的原语(例如3)是否在技术上被认为是表达式? - Are Primitives in Javascript (eg. 3) Technically Considered Expressions? 如何用Javascript逐渐改变属性值? 例如。 缓入缓出 - How to gradually change attribute values with Javascript? eg. Ease-in, Ease-out 如何检查一个Javascript数组,该数组至少包含一个以特定文本开头的值(例如ROLE_) - How to check a Javascript array that contains at least one value that starts with a particular text (eg. ROLE_) 什么是纯 JavaScript 的“hasClass”函数? - What is the "hasClass" function with plain JavaScript? Javascript Date Regex例如。 2010-06-03 - Javascript Date Regex eg. 2010-06-03 在javascript变量名中使用冒号(例如a:b:c) - Using colons in javascript variable names (eg. a:b:c) 在Javascript中轻松添加值数组(例如,无循环) - Easily add an array of values in Javascript (eg. without loops) 要显示的格式数字,例如。 “27.0 °C”使用查询和/或 javascript - Format number to show eg. “27.0 °C” using query and/or javascript 我知道如何使用javascript(getElementById)更改文本,但是如何使该文本包含例如。 链接? - I know how to change text using javascript (getElementById), but how do I make that text include eg. links?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM