回答編集履歴

1

コード追加

2020/02/05 13:47

投稿

hatena19
hatena19

スコア33744

test CHANGED
@@ -11,3 +11,33 @@
11
11
  });
12
12
 
13
13
  ```
14
+
15
+ ```html
16
+
17
+ <button id="btn1">ボタン</button>
18
+
19
+ <input id="hennkou">
20
+
21
+ ```
22
+
23
+
24
+
25
+ ---
26
+
27
+ ボタンをクリックするたびに、input と textarea が交互に切り替わる場合のコード例
28
+
29
+ ```js
30
+
31
+ $(document).on('click', '#btn1', function() {
32
+
33
+ let tar = $("#hennkou");
34
+
35
+ let tag = (tar.prop("tagName") === 'INPUT') ?
36
+
37
+ '<textarea id="hennkou"></textarea>' : '<input id="hennkou">';
38
+
39
+ tar.replaceWith(tag);
40
+
41
+ });
42
+
43
+ ```