2011-11-18 4 views
1

일부 checkBoxes가 포함 된 사용자 지정 asp.net 컨트롤이 있습니다. 나는 그 특정 div의 모든 확인란을 클릭하여 가져 오기

$('#customer-category-control input:checkbox').click(function(event) 
{ 
    var el = $(this).attr('name'); 
}; 

을 클릭 한 확인란을 얻는 방법을 알고 저를 제안, 어떻게에만 모든 클릭에 의해 체크 박스를 확인 얻고 그들의 이름에서 JSON 객체를 만들하시기 바랍니다.

+0

흠 ... 내가 다른 요소를 혼합 모든 종류의 이벤트를 참조하십시오. 왜 '체크 박스'에서 클릭 이벤트를 듣고 싶습니까? 먼저'change' 이벤트를 첨부하고,'submit' 이벤트를 잡을 때'$ ('customer-category-control input : checkbox : checked')'를 사용하여 체크 된 체크리스트의 목록을 얻을 수 있습니다. – Shef

답변

4
var names=[]; 
$('#customer-category-control input[type="checkbox"]:checked').each(function (i, el){ 
    names.push(el.name); 
    }); 
console.log(names); // => ['foo','bar'...] 
2

이 시도 :

var obj = []; 
$('#customer-category-control input[type=checkbox]:checked').each(function(index, value) { 
    obj.push($(this).attr("name")); 
}); 
+0

나는 그것을 클릭으로해야만한다. – Alexandre

+0

어디를 클릭 하시겠습니까? 너는 그걸 언급하지 않았다. –

0
$(document).ready(function() 
     { 
      $('#customer-category-control input:checkbox').click(function(event) 
       { 
       var obj = []; 
       $('#customer-category-control input[type=checkbox]:checked').each(function(index, value) 
        { obj.push($(this).attr("name"));  }); 
alert(obj); 

      }); 
     }); 
관련 문제