在jquery.ui.accordion.js的源代码中,它只是一个包含新选择的元素的对象。
// find elements to show and hide
var toShow = clicked.next(),
toHide = this.active.next(),
data = {
options: options,
newHeader: clickedIsActive && options.collapsible ? $([]) : clicked,
oldHeader: this.active,
newContent: clickedIsActive && options.collapsible ? $([]) : toShow,
oldContent: toHide
},
down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] );
this.active = clickedIsActive ? $([]) : clicked;
this._toggle( toShow, toHide, data, clickedIsActive, down );
return;
},
newHeader不是数组,而是表示新选定元素的对象。您发布的代码在accordion元素中找到所有h3元素,然后获取newHeader的索引。每次手风琴更改时,newHeader表示的元素都会更改。