3

サイトにリスト アイテムを操作するための展開/折りたたみボタンがあります。ただし、すべてを折りたたむと、最初のアイテムも含めてすべてが消えます。そこから私の唯一の選択肢は、すべてを展開して何でも見ることができるようにすることです。

JS:

function prepareList() {
  $('#expList').find('li:has(ul)').click( function(event) {
      if (this == event.target) {
        $(this).toggleClass('expanded');
        $(this).children('ul').toggle('medium');
      }
      return false;
    })
    .addClass('collapsed').children('ul').hide();

        //Create the toggle 
        var toggle = false;
      $('#listToggle').unbind('click').click(function(){
        if(toggle == false){
          $('.collapsed').addClass('expanded');
          $('.collapsed').children().show('medium');
          $('#listToggle').text("Collapse All");
          toggle = true;
        }else{
          $('.collapsed').removeClass('expanded');
          $('.collapsed').children().hide('medium');
          $('#listToggle').text("Expand All");
          toggle = false;          
        }
      });

  $('#expList').find('li').click( function(event) {
    siteUrl =  $(this).attr('value');
      if(this.id != 'myList'){
                  RefreshSiteLists(siteUrl);
              } else{
                  RefreshSiteLists(siteUrl);
              }
              return false;
    });
}

HTML: http://jsfiddle.net/9HxGp/

基本的に倒れたら全部消えます。<span>これは、テキストの周りにa を追加した場合にのみ発生します。

ここに画像の説明を入力

4

2 に答える 2

1

子セレクターと関係があるようです。私はjsfiddleを修正して実行しました-上記の私のコメントを参照してください。必要だったのは、ボタンのクリック ハンドラーのセレクターを微調整することだけで、最終的には次のようになりました。

$('#listToggle').unbind('click').click(function(){
    if(toggle == false){
      $('.collapsed').addClass('expanded');
      $('.collapsed').children().show('medium').children().show(); //needed to add a second level to make everything show here for some reason
      $('#listToggle').text("Collapse All");
      toggle = true;
    }else{
      $('.collapsed').removeClass('expanded');
      $('.collapsed').find('li').hide('medium'); //specifically hides li children
      $('#listToggle').text("Expand All");
      toggle = false;          
    }
  });

注: 下位レベルのメニュー項目が折りたたまれるように意図されているかどうかはわかりません。

http://jsfiddle.net/9HxGp/4/

于 2013-10-23T20:07:43.803 に答える