javascript - jquery disable checkbox by default -
my current script toggling between disabled , enabled.
<script> $("#filter").attr('checked', !$("#mylist")[0].disabled); $("#filter").click(function() { $("#mylist").attr('disabled', !this.checked) }); </script>
and html code is:
<div> <div class="checkbox"> <input type="checkbox" checked="checked" id="filter" /> <label for="filter">types</label> <br> </div> <select class="selectpicker" id="mylist" multiple> <option>a</option> <option>b</option> <option>c</option> </select> </div>
by default checkbox checked, , when remove `checked="checked" , doesn't work @ all.
how can disable default , enable/disable afterwards?
are need .if uncheck = disable
,check=enable
.in default case unchecked
disable
.change default checked
enable
$(document).ready(function (){ $("#filter").attr('checked', false); if(!$("#filter").attr('checked')){ $("#mylist").attr('disabled',"true"); } $("#filter").click(function() { $("#mylist").attr('disabled', !this.checked); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <div class="checkbox"> <input type="checkbox" id="filter" /> <label for="filter">types</label> <br> </div> <select class="selectpicker" id="mylist" multiple> <option>a</option> <option>b</option> <option>c</option> </select> </div>
Comments
Post a Comment