jQuery Accordion: links don't work

后端 未结 9 549
终归单人心
终归单人心 2020-12-06 08:44

I\'m working on a page using jQuery\'s accordion UI element. I modeled my HTML on that example, except that inside the

  • elements, I have some unordere
  • 相关标签:
    9条回答
    • 2020-12-06 09:09

      Solution http://www.colorizate.com/jquery-acordion-hack-link-interno/

      0 讨论(0)
    • 2020-12-06 09:11

      By default, the accordian widget sets all the links to headers. To change it, you need to specify a selector with the headers option. So, your code would look like this:

      $(".ui-accordion-container").accordion(
         { active: "a.default", ...,  header: "a.accordion-label" }
      );
      
      0 讨论(0)
    • 2020-12-06 09:13

      May be my suggestion is not using accordion() function, [ which i didn't know about before, Thank you for bring it up :) ] but still show how to have have an Accordion UI Element.

      HTML

      <body id="body">
          <h2>Accordian</h2>
              <div id="accordion" class="">
      
                      <div class="toggle_all">
                              <ul class="links">
                                      <li><a class="openall" href="#"><span>Open All</span></a></li>
                                      <li>|</li>
                                      <li><a class="closeall" href="#"><span>Close All</span></a></li>
                              </ul>
                      </div>
      
                      <!-- toggleAll ends -->
                      <div class="accordion">
                              <div class="section_title_accordion design-gray">
                                      <h3><a href="#" class="open"><span>Lorem ipsum</span></a></h3>
                              </div>
                              <!-- section_title_accordion ends -->
                              <div class="accordion_content"> <span class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> </div>
      
                              <!-- accordion_content ends -->
                      </div>
                      <!-- accordion ends -->
                      <div class="accordion">
                              <div class="section_title_accordion design-gray">
                                      <h3><a href="#" class="open"><span>Lorem ipsum</span></a></h3>
                              </div>
                              <!-- section_title_accordion ends -->
      
                              <div class="accordion_content"> <span class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> </div>
                              <!-- accordion_content ends -->
                      </div>
                      <!-- accordion ends -->
                      <div class="accordion">
                              <div class="section_title_accordion design-gray">
                                      <h3><a href="#" class="open"><span>Lorem ipsum</span></a></h3>
      
                              </div>
                              <!-- section_title_accordion ends -->
                              <div class="accordion_content"> <span class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> </div>
                              <!-- accordion_content ends -->
                      </div>
                      <!-- accordion ends -->
              </div>
      
              <!-- #accordion ends -->
      </body>
      

      CSS

      <style type="text/css" >
      #body { margin-left:20%; font:12px verdana; }
      .accordion { width:500px; }
      h3 { margin:0; padding:0; }
      .section_title_accordion { float:left; width:500px; margin:2px 0 0; }
      .section_title_accordion h3 span { margin:0; float:left; color:#fff; padding:2px 0 3px 10px; }
      .section_title_accordion a span { padding-left:20px; }
      .accordion_content { border-bottom:1px solid #666666; border-left:1px solid #666666; border-right:1px solid #666666; float:left; padding:5px 3px; }
      .accordion_content span.content { margin:5px 0 0; }
      .design-gray { background:#003366; }
      .design-gray a { color:#fff; float:left; width:100%; height:22px; background:#003366; text-decoration:none; }
      .design-gray a:hover { text-decoration:underline;}
      .on .design-gray a { color:#fff; float:left; width:100%; height:22px; background:#003366;}
      .accordion_content_hover { background:#ffffcc; color:#000099; }
      .toggle_all { padding:20px 0; width:500px; margin-bottom:5px; }
      .toggle_all ul { padding:0; margin:0; }
      .toggle_all ul li { list-style-type:none; }
      .toggle_all .links li { float:left; padding-left:5px; }
      .toggle_all .links li a, .toggleAll .links span { color:#666666; }
      </style>
      

      jQuery

      <script language="javascript" type="text/javascript">
      
      $(document).ready(function() {
        $(".accordion_content").hide();
        $("a.open").click(function() {
          $(this).parents(".accordion").find(".accordion_content").toggle();
              $(this).parents(".accordion").toggleClass('on');    
              return false;
        });   
      
          $(".accordion_content").mouseover(function() {
                  $(this).addClass('accordion_content_hover');
                  return false;       
          });
      
          $(".accordion_content").mouseout(function() {
                  $(this).removeClass('accordion_content_hover');
                  return false;       
          });
      
          $("a.openall").click(function() {
              $(".accordion_content").show();
              $(this).parents("#accordion").find(".accordion").addClass('on');
              return false;
          });
          $("a.closeall").click(function() {
                $(".accordion_content").hide();
                $(this).parents("#accordion").find(".accordion").removeClass('on');
              return false;
          });
      });
      </script>
      

      Hope this helps.

      0 讨论(0)
    提交回复
    热议问题