[jQuery] フォームの値をクリア、リセット、空にする方法
jQuery でフォームの値をクリアする方法をご紹介します。
var clearAllFormValues = function() { $('input,textarea') .not('input[type=\"radio\"],input[type=\"checkbox\"],:hidden, :button, :submit,:reset') .val(''); $('input[type=\"radio\"], input[type=\"checkbox\"],select') .removeAttr('checked') .removeAttr('selected'); } |
// div#modal-area 内のフォームの値をクリアする var clearModalAreaFormValues = function() { $('#modal-area') .find('input,textarea') .not('input[type=\"radio\"],input[type=\"checkbox\"],:hidden, :button, :submit,:reset') .val(''); $('#modal-area') .find('input[type=\"radio\"], input[type=\"checkbox\"],select') .removeAttr('checked') .removeAttr('selected'); } |
jQuery を使っている現場からは以上です。