javascript フォームの値を削除する
- 2020.08.24
- javascript
- javascript

javascriptを使って入力したフォームの値を削除するサンプルコードを記述してます。
環境
- OS windows10 pro 64bit
- Apache 2.4.43
※windows10にApacheのインストールはこちら
値削除
クリア ボタンをクリックすれば、入力したテキストの値を削除することができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>mebeeサンプル</title> <!-- UIkit CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.5.5/dist/css/uikit.min.css" /> <!-- UIkit JS --> <script src="https://cdn.jsdelivr.net/npm/uikit@3.5.5/dist/js/uikit.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/uikit@3.5.5/dist/js/uikit-icons.min.js"></script> </head> <style> .container { margin: 0 auto; margin-top: 200px; display: flex; flex-direction: column; align-items: center; font-size: 30px; } </style> <script> function clearText() { var txtVal = document.getElementById("txt"); txtVal.value = ''; } </script> <body> <div class="container"> <form> <fieldset class="uk-fieldset"> <legend id="txt" class="uk-legend">text</legend> <div class="uk-margin"> <input class="uk-input" type="text"> </div> <button class="uk-button uk-button-danger" onclick="clearText()">クリア</button> </fieldset> </form> </div> </body> </html> |
実行結果を確認すると入力したフォームの内容が削除されていることが確認できます。

-
前の記事
javascript 前と後ろにある空白を全て削除する 2020.08.24
-
次の記事
php PHP_CodeSnifferを使用して構文チェックを行う 2020.08.24
コメントを書く