Form reset causes issues (jQuery)
$(function () {
function f1() {
if (this.checked) {
$('select[name=two]').removeAttr('disabled');
} else {
$('select[name=two]').attr('disabled', true);
}
}
$('input[name=one]').change(f1).triggerHandler('change');
$('.reset').click(function () {
$('input[name=one]').removeAttr('checked').end().click(f1);
})
});
... almost works. Please check fiddle here.
But the problem is:
- Check 'one' and select 'two' from dropdown.
- Click 'reset'.
- Check 'one' again and try selecting 'two' from dropdown.
Dropdown gets disabled automatically!
Many thanks for you开发者_StackOverflow中文版r help!
You should rather trigger the change handler during reset. Replace
$('input[name=one]').removeAttr('checked').end().click(f1);
by
$('input[name=one]').removeAttr('checked').triggerHandler('change');
Here's a new fork.
精彩评论