更新时间:2023-02-12 21:11:20
这是您要实现的目标吗?
Is this what you are trying to achieve?
$("h2").click(function () {
$("h2").not(this).parent().next().hide();
$(this).parent().next().show();
});
说明:
H2
,除了单击的以外,转到父级(包含H2
的DIV
),获取下一个元素(包含内容的DIV
),隐藏所有包含的DIV
内容H2
进行遍历,确保显示包含内容的DIV
H2
s, except the clicked one, go to parent (DIV
containing the H2
s), get next element (DIV
with content), hide all the DIV
s containing contentH2
, traverse in the similar manner, make sure the DIV
with content is shown