开发者

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:

  1. Check 'one' and select 'two' from dropdown.
  2. Click 'reset'.
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜