質問編集履歴

4

訂正コードも修正

2018/09/30 22:50

投稿

pegy
pegy

スコア243

test CHANGED
File without changes
test CHANGED
@@ -48,49 +48,49 @@
48
48
 
49
49
  </head>
50
50
 
51
- <body>
51
+ <body>
52
52
 
53
53
 
54
54
 
55
- <script type="text/javascript">
55
+  <script type="text/javascript">
56
56
 
57
- //Javascript変数定義
57
+   //Javascript変数定義
58
58
 
59
- var content =new Array();
59
+   var content =new Array();
60
60
 
61
- $(document).ready(function(){
61
+   $(document).ready(function(){
62
62
 
63
-   $.ajax({
63
+    $.ajax({
64
64
 
65
-   url: 'https://www.xyz',// http://から始まるURLを指定
65
+    url: 'https://www.xyz',// http://から始まるURLを指定
66
66
 
67
-   type: 'GET',
67
+    type: 'GET',
68
68
 
69
-   success: function(res) {
69
+    success: function(res) {
70
70
 
71
- var content =new Array();
71
+   var content =new Array();
72
72
 
73
- $(res.responseText).find('.link').each(function(){
73
+   $(res.responseText).find('.link').each(function(){
74
74
 
75
- content.push($(this).attr('href'));//ここです
75
+   content.push($(this).attr('href'));//ここです
76
76
 
77
- })
77
+   })
78
78
 
79
-     console.log(content);//local scopeのため出力される
79
+      console.log(content);//local scopeのため出力される
80
80
 
81
-   }
81
+    }
82
+
83
+   });
82
84
 
83
85
   });
84
86
 
85
- });
86
-
87
- console.log(content);//globalscopeのため出力されない
87
+   console.log(content);//globalscopeのため出力されない
88
88
 
89
89
 
90
90
 
91
- </script>
91
+  </script>
92
92
 
93
- </body>
93
+ </body>
94
94
 
95
95
  </html>
96
96
 
@@ -148,13 +148,13 @@
148
148
 
149
149
  var content =new Array();
150
150
 
151
- $.ajax({
151
+   $.ajax({
152
152
 
153
- url: 'https://www.xyz',// http://から始まるURLを指定
153
+   url: 'https://www.xyz',// http://から始まるURLを指定
154
154
 
155
- type: 'GET',
155
+   type: 'GET',
156
156
 
157
- success: function(res) {
157
+    success: function(res) {
158
158
 
159
159
  $(res.responseText).find('.link').each(function(){
160
160
 
@@ -164,21 +164,21 @@
164
164
 
165
165
 
166
166
 
167
- // console.log(content);
167
+    // console.log(content);
168
168
 
169
- }
169
+    }
170
170
 
171
- });
171
+   });
172
+
173
+   
174
+
175
+   console.log(content);
176
+
177
+   });
172
178
 
173
179
 
174
180
 
175
- console.log(content);
176
-
177
- });
178
-
179
-
180
-
181
- </script>
181
+   </script>
182
182
 
183
183
  </body>
184
184
 

3

インデントを修正しました。

2018/09/30 22:50

投稿

pegy
pegy

スコア243

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  ```html
34
34
 
35
- ~~<!DOCTYPE html>
35
+ <!DOCTYPE html>
36
36
 
37
37
  <html lang="ja" dir="ltr">
38
38
 
@@ -60,13 +60,13 @@
60
60
 
61
61
  $(document).ready(function(){
62
62
 
63
- $.ajax({
63
+   $.ajax({
64
64
 
65
- url: 'https://www.xyz',// http://から始まるURLを指定
65
+   url: 'https://www.xyz',// http://から始まるURLを指定
66
66
 
67
- type: 'GET',
67
+   type: 'GET',
68
68
 
69
- success: function(res) {
69
+   success: function(res) {
70
70
 
71
71
  var content =new Array();
72
72
 
@@ -76,13 +76,11 @@
76
76
 
77
77
  })
78
78
 
79
+     console.log(content);//local scopeのため出力される
79
80
 
81
+   }
80
82
 
81
- console.log(content);//local scopeのため出力される
82
-
83
- }
84
-
85
- });
83
+  });
86
84
 
87
85
  });
88
86
 
@@ -94,7 +92,7 @@
94
92
 
95
93
  </body>
96
94
 
97
- </html>~~
95
+ </html>
98
96
 
99
97
  ```
100
98
 

2

修正

2018/09/30 22:48

投稿

pegy
pegy

スコア243

test CHANGED
File without changes
test CHANGED
@@ -152,13 +152,13 @@
152
152
 
153
153
  $.ajax({
154
154
 
155
- url: 'https://www.nikkei.com/news/jinji/hatsurei/',// http://から始まるURLを指定
155
+ url: 'https://www.xyz',// http://から始まるURLを指定
156
156
 
157
157
  type: 'GET',
158
158
 
159
159
  success: function(res) {
160
160
 
161
- $(res.responseText).find('.m-articleTitle_text_link').each(function(){
161
+ $(res.responseText).find('.link').each(function(){
162
162
 
163
163
  content.push($(this).attr('href'));
164
164
 
@@ -174,7 +174,7 @@
174
174
 
175
175
 
176
176
 
177
- console.log('<a href="https://www.nikkei.com/'+content[0]+'"></a>');
177
+ console.log(content);
178
178
 
179
179
  });
180
180
 

1

修正コードを記載しました。

2018/09/26 08:14

投稿

pegy
pegy

スコア243

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  ```html
34
34
 
35
- <!DOCTYPE html>
35
+ ~~<!DOCTYPE html>
36
36
 
37
37
  <html lang="ja" dir="ltr">
38
38
 
@@ -94,7 +94,7 @@
94
94
 
95
95
  </body>
96
96
 
97
- </html>
97
+ </html>~~
98
98
 
99
99
  ```
100
100
 
@@ -113,3 +113,77 @@
113
113
  初歩的な内容であれば誠に申し訳ございませんが
114
114
 
115
115
  宜しくお願い申し上げます。
116
+
117
+
118
+
119
+ 修正コードの加筆
120
+
121
+ ```html
122
+
123
+ <!DOCTYPE html>
124
+
125
+ <html lang="ja" dir="ltr">
126
+
127
+ <head>
128
+
129
+ <meta charset="utf-8">
130
+
131
+ <title>script</title>
132
+
133
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
134
+
135
+ <script type="text/javascript" src="xdomain.js"></script>
136
+
137
+ </head>
138
+
139
+ <body>
140
+
141
+
142
+
143
+ <script type="text/javascript">
144
+
145
+ //Javascript変数定義
146
+
147
+
148
+
149
+ $(document).ready(function(){
150
+
151
+ var content =new Array();
152
+
153
+ $.ajax({
154
+
155
+ url: 'https://www.nikkei.com/news/jinji/hatsurei/',// http://から始まるURLを指定
156
+
157
+ type: 'GET',
158
+
159
+ success: function(res) {
160
+
161
+ $(res.responseText).find('.m-articleTitle_text_link').each(function(){
162
+
163
+ content.push($(this).attr('href'));
164
+
165
+ })
166
+
167
+
168
+
169
+ // console.log(content);
170
+
171
+ }
172
+
173
+ });
174
+
175
+
176
+
177
+ console.log('<a href="https://www.nikkei.com/'+content[0]+'"></a>');
178
+
179
+ });
180
+
181
+
182
+
183
+ </script>
184
+
185
+ </body>
186
+
187
+ </html>
188
+
189
+ ```