简体   繁体   中英

enable multiple checkboxes when a checkbox is checked

I have 5 text boxes whose IDs and names are all different from each other. But i have to enable all 5 text boxes when a certain checkbox is checked. How do i do this with JavaScript?

With jQuery you can do

<input id="check" type="checkbox" value=""><br>
<input type="text" value="" disabled="disabled"><br>
<input type="text" value="" disabled="disabled"><br>
<input type="text" value="" disabled="disabled"><br>

var $input = $('input[type="text"]');
$('#check').live('click', function() {
    $(this).is(':checked') ? $input.removeAttr('disabled') : $input.attr('disabled', 'disabled');
})

Check working example at http://jsfiddle.net/CpmkE/3/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM