如何手动触发 jQuery 切换面板
我正在使用这个小提琴上显示的 jQuery 和 HTML,并且我一生都无法手动触发单个选项卡。
$("h3").toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom").find(".ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end().next().slideToggle();
上面的 jQuery 将切换所有元素,但是如果我引用个人以这种方式: $("#ToggleHeader").etc 这是行不通的。
我希望得到一些帮助,并希望能解释为什么这对我不起作用。
I am using the jQuery and HTML shown on this fiddle and for the life of me am not able to manually fire individual tabs.
$("h3").toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom").find(".ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end().next().slideToggle();
The above jQuery will toggle all of the elements, but if I reference an individual in this manner:
$("#ToggleHeader").etc
it will not work.
I'd love some help and hopefully an explanation why this isn't working for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试的解决方案不起作用,因为选择器
$("h3")
与页面上的每个h3
匹配,因此以下操作将应用于所有这些。您尝试的第二个解决方案不起作用,因为 html 代码中的h3
元素没有任何 id。为每个元素添加一个 id,然后使用 id 选择器
$("#ToggleHeader")
等选择标头。
The solution you tried doesn't work because the selector
$("h3")
matches everyh3
on the page, so the operations that follow are applied to all of them. The second solution you tried didn't work because theh3
elements in your html code do not have any ids.Add an id to each element, and then select the header using the id selector
$("#ToggleHeader")
etc..