| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン |
| study:javascript:jquery:clear-form [2011/03/28 09:16] – [demo] banana | study:javascript:jquery:clear-form [2017/11/28 04:26] (現在) – [code snippet] banana |
|---|
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| <title>demo page for form reset using jQuery</title> | <title>demo page for form reset using jQuery</title> |
| |
| <link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" /> | |
| |
| <script type="text/javascript" src="./test/js/jquery-1.4.2.js"></script> | <script type="text/javascript" src="./test/js/jquery-1.4.2.js"></script> |
| function clearForm(){ | function clearForm(){ |
| if(confirm('データをクリアにしてよろしいですか?')){ | if(confirm('データをクリアにしてよろしいですか?')){ |
| $("input[type='text'], textarea").not("input[readonly='true'], :hidden, :button, :submit, :reset").val(""); | $("input[type='text'], textarea").not("input[readonly='true'], input[type='hidden'], :button, :submit, :reset").val(""); |
| $("input[type='radio'], input[type='checkbox'], select").removeAttr("checked").removeAttr("selected"); | $("input[type='radio'], input[type='checkbox'], select").removeAttr("checked").removeAttr("selected"); |
| $("select option:first-child").attr("selected", "selected"); | $("select option:first-child").attr("selected", "selected"); // 1.6以前のバージョン |
| | $("select").prop("selectedIndex", "0"); // 1.6以降 |
| } | } |
| } | } |