반응형


체크박스 체크된 값만 가져오기 (checkbox checked valuese)


<body>

<form:form commandName="" id="listForm" name="listForm">

<button type="button" id="expsrYn1" name="expsrYn" class="btn btnexpsrYn">노출</button> 

<button type="button" id="expsrYn2" name="expsrYn" class="btn btnexpsrYn">비노출</button>

<input type="checkbox" name="pkList" id="PkList_1" value="no1">

<input type="checkbox" name="pkList" id="PkList_2" value="no2">

<input type="checkbox" name="pkList" id="PkList_3" value="no3">

<input type="checkbox" name="pkList" id="PkList_4" value="no4">

</form:form>

<script>

var $form = $("#listForm");

$(function() {

$form.find(".btnexpsrYn").on('click', function(e){

var chked_val = "";

$(":checkbox[name='pkList']:checked").each(function(pi,po){

    chked_val += ","+po.value;

    console.log(pi);

});

chked_val = chked_val.substring(1); // 1st (,) removed

console.log(chked_val);

});

});

</script>

</body>


반응형

+ Recent posts