回答編集履歴

1

追記しました

2016/09/09 09:18

投稿

MaShiRo_H
MaShiRo_H

スコア328

test CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  $(function(){
10
10
 
11
+ //もはやedit_offじゃなくても良いのですが、そのまま流用しています
12
+
11
13
  $('.edit_off').each(function(){
12
14
 
13
15
  $(this).add($(this).parents("tr").find('.off')).hide();
@@ -16,15 +18,17 @@
16
18
 
17
19
  });
18
20
 
19
- var val;
21
+ //var target;はテキスト取得用、var val;は代入先用
20
22
 
21
23
  var target;
22
24
 
25
+ var val;
26
+
23
27
  $(".edit_on").click(function(){
24
28
 
29
+ target = $(this).parents("tr").find('input[type="text"]')
30
+
25
31
  val = $(this).parents("tr").find('.display_target').text()
26
-
27
- target = $(this).parents("tr").find('input[type="text"]')
28
32
 
29
33
  $(target).val(val)
30
34
 
@@ -36,9 +40,9 @@
36
40
 
37
41
  $('.edit_off').click(function(e){
38
42
 
43
+ target = $(this).parents("tr").find('.display_target')
44
+
39
45
  val = $(this).parents("tr").find('input[type="text"]').val()
40
-
41
- target = $(this).parents("tr").find('.display_target')
42
46
 
43
47
  $(target).text(val)
44
48
 
@@ -51,6 +55,10 @@
51
55
  });
52
56
 
53
57
  ```
58
+
59
+
60
+
61
+ show()、hide()を分かりやすくするために、それぞれ切り替わる対象の要素にonとoffのclassを付与しています。
54
62
 
55
63
  ```HTML
56
64