Jquery/function

[Jquery] input 초기화

꾸끄꾸꾸 2021. 5. 20. 17:25

1. input type별 초기화

function clearInputs(target) {
  $(target).find(':input').each(function () {
    switch (this.type) {
        case 'password':
        case 'select-multiple':
        case 'select-one':
        case 'text':
          $(this).val('');
        case 'textarea':
          $(this).val('');
            break;
        case 'checkbox':
        case 'radio':
          this.checked = false;
        case 'file':
          $(this).val('');
    }
  });
}

 

2. Form 초기화

$('form[name=Form]')[0].reset();