简体   繁体   English

通过jQuery自动多次运行JS函数

[英]Running a JS function automatically multiple times through jQuery

I am currently adding a feature to a genealogy website I am currently working on which is based on the Webtrees open source software. 我目前正在为正在使用的家谱网站添加一个功能,该功能基于Webtrees开源软件。

So here is where I am at: 所以这是我的位置: 在此处输入图片说明

So originally, the software allows the user to press the individual node to expand/compress its content. 因此,最初,该软件允许用户按下各个节点以扩展/压缩其内容。 And that works through the following code: 并通过以下代码工作:

TreeViewHandler.prototype.expandBox = function(j, i) {
    if (jQuery(i.target).hasClass("tv_link")) {
        return !1
    }
    j = jQuery(j, this.treeview);
    var p = j.parent(),
        o = j.attr("abbr"),
        n = this,
        l, k;
    if (p.hasClass("detailsLoaded")) {
        k = p.find(".collapsedContent"), l = p.find(".tv_box:not(.collapsedContent)")
    } else {
        l = j;
        k = j.clone();
        p.append(k.addClass("collapsedContent").css("display", "none"));
        var m = this.loadingImage.find("img").clone().addClass("tv_box_loading").css("display", "block");
        j.prepend(m);
        n.updating = !0;
        n.setLoading();
        j.load(n.ajaxUrl + "getDetails&pid=" + o, function() {
            "function" === typeof CB_Init && CB_Init();
            j.css("width", n.zoom / 100 * n.boxExpandedWidth + "px");
            m.remove();
            p.addClass("detailsLoaded");
            n.setComplete();
            n.updating = !1
        })
    }
    j.hasClass("boxExpanded") ? (l.css("display", "none"), k.css("display", "block"), j.removeClass("boxExpanded")) : (l.css("display", "block"), k.css("display", "none"), l.addClass("boxExpanded"));
    this.getSize();
    return !1
};

What I'm trying to do is I'm trying to make the button I placed on the top left, which is to expand/compress ALL boxes in one click work. 我正在尝试做的是使我放在左上角的按钮,即一键展开/压缩所有框。 The one in showing/hiding females already work. 显示/隐藏女性中的那个已经起作用。

$(document).ready(function(){
    var female = false
    $(".tv_hidefemales").click(function(){
        if (female == false) {
            $(".tvF").hide();
            female = true
        } else {
            $(".tvF").show();
            female = false
        }
    });
    $(".tv_expandCompress").click(function(){
        tvHandler.expandBox($(".tv"), 0);
    });
});

我发现我可以利用循环的jQuery .click()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM