简体   繁体   English

手风琴菜单JQuery-如何打开特定的“ id”?

[英]Accordion menu JQuery - How to open a specific “id”?

I have a menu like an appointment book with all months of the year. 我有一个菜单,像约会簿一样,一年四季都在。 I created a JQuery file to open and close this. 我创建了一个JQuery文件来打开和关闭它。

 $(function() {
var Accordion = function(el, multiple) {
    this.el = el || {};
    this.multiple = multiple || false;

    var links = this.el.find('.link');

    var d = new Date();
    var n = d.getMonth();

    var links2 = this.el.find('#mes'+n);

    // Events
    links.on('click',{el: this.el, multiple: this.multiple}, this.dropdown)

    //links2.on('',{el: this.el, multiple: this.multiple}, this.dropdown)

}

Accordion.prototype.dropdown = function(e) {
    var $el = e.data.el;
        $this = $(this),
        $next = $this.next();

    $next.slideToggle();
    $this.parent().toggleClass('open');


    if (!e.data.multiple) {
        $el.find('.submenu').not($next).slideUp().parent().removeClass('open');
    };
}   

var accordion = new Accordion($('#accordion'), false);
});

The "link" variable find the "div" to open and close when I click the mouse pointer on this. 当单击鼠标指针时,“ link”变量会找到要打开和关闭的“ div”。 It calls the "dropdown" function. 它调用“下拉”功能。

I tried to create a "link2" variable to call the specific "id". 我试图创建一个“ link2”变量来调用特定的“ id”。 So how I proceed to do a dropdown in a specific "id" when I enter in the page, without mouse clicks??? 因此,当我进入页面时,如何在没有鼠标点击的情况下继续在特定的“ id”中进行下拉?

If I understand correctly, you want one of the items to start off expanded. 如果我理解正确,您希望其中一项开始展开。 I assume links2 has class .link . 我认为links2具有类.link You can trigger a click event with links2.trigger("click"); 您可以使用links2.trigger("click");触发点击事件links2.trigger("click"); .

var Accordion = function(el, multiple) {
    this.el = el || {};
    this.multiple = multiple || false;

    var links = this.el.find('.link');

    var d = new Date();
    var n = d.getMonth();

    var links2 = this.el.find('#mes'+n);

    // Events
    links.on('click',{el: this.el, multiple: this.multiple}, this.dropdown)

    links2.trigger("click");
}

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

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