且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JQuery对HTML内容进行分页

更新时间: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,除了单击的以外,转到父级(包含H2DIV),获取下一个元素(包含内容的DIV),隐藏所有包含的DIV内容
  • 以点击的H2进行遍历,确保显示包含内容的DIV
  • Take all the H2s, except the clicked one, go to parent (DIV containing the H2s), get next element (DIV with content), hide all the DIVs containing content
  • Take the clicked H2, traverse in the similar manner, make sure the DIV with content is shown