Resetting a multi-stage form with jQuery

前端 未结 30 2391
谎友^
谎友^ 2020-11-22 00:58

I have a form with a standard reset button coded thusly:


Trouble i

30条回答
  •  粉色の甜心
    2020-11-22 01:28

    jQuery Plugin

    I created a jQuery plugin so I can use it easily anywhere I need it:

    jQuery.fn.clear = function()
    {
        var $form = $(this);
    
        $form.find('input:text, input:password, input:file, textarea').val('');
        $form.find('select option:selected').removeAttr('selected');
        $form.find('input:checkbox, input:radio').removeAttr('checked');
    
        return this;
    }; 
    

    So now I can use it by calling:

    $('#my-form').clear();
    

提交回复
热议问题