I want to disable other checkbox when current checkbox is checked or selected.
Following is my code. I have tried but not work
HTML
<input type="checkbox" name="test" id="test" class="test">One
<input type="checkbox" name="test" id="test" class="test">Two
<input type="checkbox" name="test" id="test" class="test">Three
<input type="checkbox" name="test" id="test" class="test">Four
<input type="checkbox" name="test" id="test" class="test">Five
JQuery Script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".test").each(function(){
if($(this).is(':checked')){
$(this).prop('checked',true);
$('.test').prop('checked',false);
}
})
})
</script>
Aucun commentaire:
Enregistrer un commentaire