回答編集履歴

4

chousei

2018/12/06 08:10

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -71,3 +71,47 @@
71
71
  </div>
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ # 調整版
78
+
79
+ .itemは消さない。付け足した#contentsは削除
80
+
81
+
82
+
83
+ ```javascript
84
+
85
+ $(function(){
86
+
87
+ $('.item a').on('click',function(e){
88
+
89
+ e.preventDefault();
90
+
91
+ if($(this).closest('.item').next().filter('#contents').length>0){
92
+
93
+ $('#contents').remove();
94
+
95
+ }else{
96
+
97
+ $.ajax({
98
+
99
+ url:$(this).attr('href'),
100
+
101
+ dataType:'html',
102
+
103
+ }).done(function(html){
104
+
105
+ $('#contents').remove();
106
+
107
+ $(e.target).closest('.item').after($('<div id="contents">').append(html));
108
+
109
+ });
110
+
111
+ }
112
+
113
+ });
114
+
115
+ });
116
+
117
+ ```

3

調整

2018/12/06 08:09

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  }).done(function(html){
52
52
 
53
- $(e.target).after(html).closest('.item').siblings().remove();
53
+ $(e.target).after($('<div id="contents">').append(html)).closest('.item').siblings().remove();
54
54
 
55
55
  });
56
56
 

2

tyぽ

2018/12/06 07:37

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -62,7 +62,7 @@
62
62
 
63
63
  <div class="gnavi">
64
64
 
65
- <div class="item"><a href="y.php">1のページ</a></div>
65
+ <div class="item"><a href="modal_A.html">1のページ</a></div>
66
66
 
67
67
  <div class="item"><a href="modal_B.html">2のページ</a></div>
68
68
 

1

調整

2018/12/06 07:35

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -27,3 +27,47 @@
27
27
  ```
28
28
 
29
29
  のようになるということでしょうか?
30
+
31
+
32
+
33
+ # sample
34
+
35
+ ```javascript
36
+
37
+ <script>
38
+
39
+ $(function(){
40
+
41
+ $('.item a').on('click',function(e){
42
+
43
+ e.preventDefault();
44
+
45
+ $.ajax({
46
+
47
+ url:$(this).attr('href'),
48
+
49
+ dataType:'html',
50
+
51
+ }).done(function(html){
52
+
53
+ $(e.target).after(html).closest('.item').siblings().remove();
54
+
55
+ });
56
+
57
+ });
58
+
59
+ });
60
+
61
+ </script>
62
+
63
+ <div class="gnavi">
64
+
65
+ <div class="item"><a href="y.php">1のページ</a></div>
66
+
67
+ <div class="item"><a href="modal_B.html">2のページ</a></div>
68
+
69
+ <div class="item"><a href="modal_C.html">3のページ</a></div>
70
+
71
+ </div>
72
+
73
+ ```