using jquery, what is the easiest way to disable and enable a section of html input controls
i have a bunch of form inputs (textboxex, radio buttons, checkboxes, etc)
there is a specific section of the form that i want to enable and disable.
i want a quick way when i click on a radio button (which is not part of the form) to disable all inputs in this specific section of a form. also on the selection of a different radio button (also not on the form in question) to enable that same section of the form input controls.
The one trick is that i dont fully have control over the id and classes of the a开发者_高级运维ctual inputs so i need something where i can put a parent div and have it find all items within that div
is there an easy way in jquery to enable or disable a section of input controls.
Use the :input
selector which grabs all inputs, textareas, selects and buttons, providing a context to jQuery()
will limit this to inputs inside a parent, then change the disabled
attribute:
$(':input', parent).attr('disabled', 'disabled');
Removing the disabled attribute will re-enable:
$(':input', parent).removeAttr('disabled');
You can disable a div by adding the "disabled" attribute like this:
$('div.container').attr('disabled', 'disabled');
You can then re-enable it by removing the attribute:
$('.someElement').removeAttr('disabled');
In your case, add a click handler to your radio button or other control which uses the above lines of code to enable/disable the div element (and, by extension, all of its content), like this (for disabling):
$('#radio-button1').click(function() {
$('div.container').attr('disabled', 'disabled');
});
The first way I can think of to do this is to insert/remove the word "disabled" into the inputs you want to manipulate. You could do this with the appendTo() or html() functions selecting all inputs which match a certain id/class name.
$('#your_div_name').find('input').disable();
Needs this plugin.
精彩评论