Resetting a multi-stage form with jQuery

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

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


Trouble i

30条回答
  •  旧时难觅i
    2020-11-22 01:22

    here is my solution, which also works with the new html5 input-types:

    /**
     * removes all value attributes from input/textarea/select-fields the element with the given css-selector
     * @param {string} ele css-selector of the element | #form_5
     */
    function clear_form_elements(ele) {
        $(ele).find(':input').each(function() {
            switch (this.type) {
                case 'checkbox':
                case 'radio':
                    this.checked = false;
                default:
                    $(this).val('');
                    break;
            }
        });
    }
    

提交回复
热议问题