2011-10-19 51 views
0

我有一個嵌套的手風琴,帶有一個複選框,如果選中該複選框就會發出ajax調用,問題在於複選框在手風琴展開後不會保持檢查狀態。在jQuery手風琴中維護複選框狀態

if (childList.length > 0) { 

       list += '<ul class = ui-accordion>'; 
       for (var j = 0; j < childList.length; j++) { 

        list += '<li><div><a href="#"><input type = "checkbox" class = "reqCheckBox" value="' + childList[i].ComponentID + '"/> ' + childList[j].ComponentDesc +'</a></div>'; 

        var grandChildList = $.grep(data, function (n, k) { 
         return n.ParentID == childList[j].ComponentID; 
        }, false); 

        if (grandChildList.length > 0) { 

         list += '<ul class = ui-accordion>'; 


         for (var k = 0; k < grandChildList.length; k++) { 
          list += '<li><div><a href="#"><input type = "checkbox" onclick="getReq(' + grandChildList[i].ComponentID + ')"/>' + grandChildList[k].ComponentDesc + '</a></div>'; 

          var greatGrandChildList = $.grep(data, function (n, l) { 
           return n.ParentID == grandChildList[k].ComponentID; 
          }, false); 

          if (greatGrandChildList.length > 0) { 

           list += '<ul class = ui-accordion>'; 

           for (var l = 0; l < greatGrandChildList.length; l++) { 
            list += '<li><div><a href="#"><input type = "checkbox" onclick="getReq(' + greatGrandChildList[i].ComponentID + ')"/>' + greatGrandChildList[l].ComponentDesc + '</a></div>'; 
           } 

           list += '</li></ul>'; 
          } 
         } 

         list += '</li></ul>';** 

我知道,我需要這個不顯眼的,但我的JavaScript代碼的任何批評,以及將作爲我是一個小白可以理解的。謝謝!

回答

1

你需要的是堅持複選框的值。所以當你檢查它時,你的ajax回調需要更新一個屬性的值。當手風琴展開時,這種方式保持了複選框的狀態。

+0

我認爲這是失去了狀態,因爲點擊事件也是在發射手風琴的方法來擴展。 – marknery

+0

crocaduck81 - 它正在觸發相應的方法來擴展因爲而不是嘗試這個 Gjohn

+0

返回false沒有工作,當你說堅持複選框的狀態時,你的意思是把它存儲在cookie中? – marknery

0

我加入這個功能

 $("a").click(function (event) { 
     event.stopPropagation(); 
     }); 
    }); 
0

下保持工作狀態複選框。

$("#accordion h3 input").click(function(event) { 
event.stopPropagation(); 
});