このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
プログラム言語:javascript_jquery:フォームの値_input_selectなど_の操作 [2019/05/21 12:22] yusuke_komori [input(チェックボックス、ラジオボタン)の操作] |
プログラム言語:javascript_jquery:フォームの値_input_selectなど_の操作 [2025/10/15 18:22] (現在) humolife [複数選択可(配列)の checkbox(チェックボックス)の操作] |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== 【jQuery】フォームの値(input、selectなど)の操作 ====== | ====== 【jQuery】フォームの値(input、selectなど)の操作 ====== | ||
| コピペして test.html などの htmlファイルとして保存すれば、そのまま動作確認が行なえます。 | コピペして test.html などの htmlファイルとして保存すれば、そのまま動作確認が行なえます。 | ||
| - | ===== input の値(value)の操作 ===== | + | ===== input text の操作 ===== |
| < | < | ||
| < | < | ||
| 行 9: | 行 9: | ||
| </ | </ | ||
| < | < | ||
| + | |||
| <input type=" | <input type=" | ||
| <button type=" | <button type=" | ||
| <button type=" | <button type=" | ||
| + | |||
| < | < | ||
| $(function() { | $(function() { | ||
| 行 43: | 行 45: | ||
| </ | </ | ||
| - | ===== input(チェックボックス、ラジオボタン)の操作 ===== | + | ===== radio、checkbox(ラジオボタン、チェックボックス)の操作 ===== |
| < | < | ||
| < | < | ||
| 行 51: | 行 53: | ||
| </ | </ | ||
| < | < | ||
| + | |||
| 性別 | 性別 | ||
| < | < | ||
| 行 58: | 行 61: | ||
| <button type=" | <button type=" | ||
| <button type=" | <button type=" | ||
| + | |||
| < | < | ||
| $(function() { | $(function() { | ||
| 行 88: | 行 92: | ||
| // チェック状態(checked)を prop で解除 | // チェック状態(checked)を prop で解除 | ||
| $(' | $(' | ||
| + | }); | ||
| + | }); | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== 複数選択可(配列)の checkbox(チェックボックス)の操作 ===== | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <meta charset=" | ||
| + | <script src=" | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <button type=" | ||
| + | <button type=" | ||
| + | |||
| + | < | ||
| + | $(function() { | ||
| + | let checked = [1, 3]; | ||
| + | $(' | ||
| + | // val にチェックしたい value の配列をそのまま渡せばOK | ||
| + | $(' | ||
| + | }) | ||
| + | |||
| + | $(' | ||
| + | let status = $(' | ||
| + | return $(this).val() | ||
| + | }).get() | ||
| + | console.log(status) | ||
| + | }) | ||
| + | }) | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== select(セレクトボックス)の操作 ===== | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <meta charset=" | ||
| + | <script src=" | ||
| + | </ | ||
| + | < | ||
| + | |||
| + | <select name=" | ||
| + | <option value=""> | ||
| + | <option value=" | ||
| + | <option value=" | ||
| + | <option value=" | ||
| + | </ | ||
| + | <button type=" | ||
| + | <button type=" | ||
| + | <button type=" | ||
| + | |||
| + | < | ||
| + | $(function() { | ||
| + | $(' | ||
| + | // class で選択中の値(value)を取得 | ||
| + | let age_class = $(' | ||
| + | console.log(age_class); | ||
| + | |||
| + | // name で選択中の値(value)を取得 | ||
| + | let age_name = $(' | ||
| + | console.log(age_name); | ||
| + | }); | ||
| + | |||
| + | $(' | ||
| + | // 選択状態(selected)の変更 | ||
| + | $(' | ||
| + | }); | ||
| + | |||
| + | $(' | ||
| + | // 選択状態(selected)の変更 | ||
| + | $(' | ||
| + | }); | ||
| + | |||
| + | $(' | ||
| + | // 選択状態(selected)の解除 | ||
| + | $(' | ||
| }); | }); | ||
| }); | }); | ||