jQuery:next和nextAll

jQuery:next和nextAll,jquery,Jquery,在代码中,您能否解释为什么第一个警报在单击维护按钮时显示正确的字段集id,而第二个警报在单击子文件维护按钮时显示正确的字段集id,而不是相反 <div> <table width="100%"> <col width="25%" /> <col width="75%" /> <tr> <td> <div class="width300"><h1>Inandrias Soft

在代码中,您能否解释为什么第一个警报在单击维护按钮时显示正确的字段集id,而第二个警报在单击子文件维护按钮时显示正确的字段集id,而不是相反

<div>
 <table width="100%">
  <col width="25%" />
  <col width="75%" />
  <tr>
   <td>
    <div class="width300"><h1>Inandrias Software&#174;</h1></div>
   </td>
   <td>
    <div class="nopadormarg" style="white-space:nowrap;">
     <h1><font size=+1>You are logged in as </font>charlie<font size=+1> of New Enterprises (Pty) Ltd.</font></h1>
    </div>
   </td>
  </tr>
 </table>

 <div id="menudiv" class="nopadormarg">

    <a href="#" class="menuA" name="level01"><span>Maintenance</span></a>
      <fieldset id="Maintenance" class="menuAbuttons">
        <p>
          <a href="#" class="menuA" name="level02" title="Maintain ancilliary files"><span>Subfile maint</span></a>
            <fieldset id="Subfilemaint" class="menuAbuttons">
              <p>
                <a href="#" class="menuA" name="level03" title="Add, amend, delete (unused) Products"><span>Products</span></a>
              </p>
              <p>
                <a href="#" class="menuA" name="level03" title="Add, amend, delete (unused) Insurers"><span>Insurers</span></a>
              </p>
              <p>
                <a href="#" class="menuA" name="level03" title="Add, amend, delete (unused) Section types"><span>Section types</span></a>
              </p>
              <p>
                <a href="#" class="menuA" name="level03" title="Add, amend, delete (unused) Agents"><span>Agents</span></a>
              </p>
              <p>
                <a href="#" class="menuA" name="level03" title="Add, amend, delete (unused) Pay methods"><span>Pay methods</span></a>
              </p>
            </fieldset>
        </p>
      </fieldset>

 </div>
</div>

欢迎来到堆栈溢出!今后,请在您的帖子中包含所有相关代码,不要只包含指向JSFIDLE的链接。你的文章应该独立于任何其他资源;想想如果JsfdelDead将来发生了什么,我道歉,Matt,我试图减少杂乱。谢谢你的欢迎!
$(document).ready(function() {
    $(".menuA").click(function(evnt) {
        evnt.preventDefault();

        alert("next fieldset id = " + $(this).next('fieldset').attr('id'));
        alert("next fieldset id = " + 
$(this).closest('fieldset').find(".menuAbuttons:first").attr('id'));


    // remove the menuA-open class from the current and lower (numerically higher) level's
    //   class menuA objects except the one being clicked (toggled)
    var level = $(this).attr('name');
    // trying to avoid higher levels with >= doesn't seem to work
    //   nor does "[name = " + level + "][name > " + level + "]"
    $(".menuA").not(this).filter("[name = " + level + "]").removeClass("menuA-open");
    //this removes all menuA-open classes except the currently clicked one
    //$(".menuA").not(this).removeClass("menuA-open");

    // hide all other fieldset objects except the one being toggled
    $('fieldset').not($(this).next('fieldset')).hide();

    // toggle the fieldset following this link open or closed
    $("fieldset#" + $(this).text().replace(/\s+/gi,'')).toggle();

    // toggle the currently selected menuA-open class on or off
    $(this).toggleClass("menuA-open");

    });
});