質問編集履歴
4
訂正コードも修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,28 +23,28 @@
|
|
23
23
|
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
|
24
24
|
<script type="text/javascript" src="xdomain.js"></script>
|
25
25
|
</head>
|
26
|
-
|
26
|
+
<body>
|
27
27
|
|
28
|
-
<script type="text/javascript">
|
28
|
+
<script type="text/javascript">
|
29
|
-
//Javascript変数定義
|
29
|
+
//Javascript変数定義
|
30
|
-
var content =new Array();
|
30
|
+
var content =new Array();
|
31
|
-
$(document).ready(function(){
|
31
|
+
$(document).ready(function(){
|
32
|
-
|
32
|
+
$.ajax({
|
33
|
-
|
33
|
+
url: 'https://www.xyz',// http://から始まるURLを指定
|
34
|
-
|
34
|
+
type: 'GET',
|
35
|
-
|
35
|
+
success: function(res) {
|
36
|
-
|
36
|
+
var content =new Array();
|
37
|
-
|
37
|
+
$(res.responseText).find('.link').each(function(){
|
38
|
-
|
38
|
+
content.push($(this).attr('href'));//ここです
|
39
|
-
|
39
|
+
})
|
40
|
-
|
40
|
+
console.log(content);//local scopeのため出力される
|
41
|
-
|
41
|
+
}
|
42
|
+
});
|
42
43
|
});
|
43
|
-
});
|
44
|
-
console.log(content);//globalscopeのため出力されない
|
44
|
+
console.log(content);//globalscopeのため出力されない
|
45
45
|
|
46
|
-
</script>
|
46
|
+
</script>
|
47
|
-
|
47
|
+
</body>
|
48
48
|
</html>
|
49
49
|
```
|
50
50
|
|
@@ -73,22 +73,22 @@
|
|
73
73
|
|
74
74
|
$(document).ready(function(){
|
75
75
|
var content =new Array();
|
76
|
-
$.ajax({
|
76
|
+
$.ajax({
|
77
|
-
|
77
|
+
url: 'https://www.xyz',// http://から始まるURLを指定
|
78
|
-
|
78
|
+
type: 'GET',
|
79
|
-
|
79
|
+
success: function(res) {
|
80
80
|
$(res.responseText).find('.link').each(function(){
|
81
81
|
content.push($(this).attr('href'));
|
82
82
|
})
|
83
83
|
|
84
|
-
// console.log(content);
|
84
|
+
// console.log(content);
|
85
|
-
}
|
85
|
+
}
|
86
|
-
});
|
86
|
+
});
|
87
|
+
|
88
|
+
console.log(content);
|
89
|
+
});
|
87
90
|
|
88
|
-
console.log(content);
|
89
|
-
});
|
90
|
-
|
91
|
-
</script>
|
91
|
+
</script>
|
92
92
|
</body>
|
93
93
|
</html>
|
94
94
|
```
|
3
インデントを修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
```html
|
18
|
-
|
18
|
+
<!DOCTYPE html>
|
19
19
|
<html lang="ja" dir="ltr">
|
20
20
|
<head>
|
21
21
|
<meta charset="utf-8">
|
@@ -29,24 +29,23 @@
|
|
29
29
|
//Javascript変数定義
|
30
30
|
var content =new Array();
|
31
31
|
$(document).ready(function(){
|
32
|
-
$.ajax({
|
32
|
+
$.ajax({
|
33
|
-
|
33
|
+
url: 'https://www.xyz',// http://から始まるURLを指定
|
34
|
-
|
34
|
+
type: 'GET',
|
35
|
-
|
35
|
+
success: function(res) {
|
36
36
|
var content =new Array();
|
37
37
|
$(res.responseText).find('.link').each(function(){
|
38
38
|
content.push($(this).attr('href'));//ここです
|
39
39
|
})
|
40
|
-
|
41
|
-
console.log(content);//local scopeのため出力される
|
40
|
+
console.log(content);//local scopeのため出力される
|
42
|
-
}
|
41
|
+
}
|
42
|
+
});
|
43
43
|
});
|
44
|
-
});
|
45
44
|
console.log(content);//globalscopeのため出力されない
|
46
45
|
|
47
46
|
</script>
|
48
47
|
</body>
|
49
|
-
</html>
|
48
|
+
</html>
|
50
49
|
```
|
51
50
|
|
52
51
|
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -75,10 +75,10 @@
|
|
75
75
|
$(document).ready(function(){
|
76
76
|
var content =new Array();
|
77
77
|
$.ajax({
|
78
|
-
url: 'https://www.
|
78
|
+
url: 'https://www.xyz',// http://から始まるURLを指定
|
79
79
|
type: 'GET',
|
80
80
|
success: function(res) {
|
81
|
-
$(res.responseText).find('.
|
81
|
+
$(res.responseText).find('.link').each(function(){
|
82
82
|
content.push($(this).attr('href'));
|
83
83
|
})
|
84
84
|
|
@@ -86,7 +86,7 @@
|
|
86
86
|
}
|
87
87
|
});
|
88
88
|
|
89
|
-
console.log(
|
89
|
+
console.log(content);
|
90
90
|
});
|
91
91
|
|
92
92
|
</script>
|
1
修正コードを記載しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
```html
|
18
|
-
<!DOCTYPE html>
|
18
|
+
~~<!DOCTYPE html>
|
19
19
|
<html lang="ja" dir="ltr">
|
20
20
|
<head>
|
21
21
|
<meta charset="utf-8">
|
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
</script>
|
48
48
|
</body>
|
49
|
-
</html>
|
49
|
+
</html>~~
|
50
50
|
```
|
51
51
|
|
52
52
|
|
@@ -55,4 +55,41 @@
|
|
55
55
|
2) 上記のJavascriptのコードでphpと同様にglobalでもその配列型変数を利用するすべはあるのでしょうか?
|
56
56
|
|
57
57
|
初歩的な内容であれば誠に申し訳ございませんが
|
58
|
-
宜しくお願い申し上げます。
|
58
|
+
宜しくお願い申し上げます。
|
59
|
+
|
60
|
+
修正コードの加筆
|
61
|
+
```html
|
62
|
+
<!DOCTYPE html>
|
63
|
+
<html lang="ja" dir="ltr">
|
64
|
+
<head>
|
65
|
+
<meta charset="utf-8">
|
66
|
+
<title>script</title>
|
67
|
+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
|
68
|
+
<script type="text/javascript" src="xdomain.js"></script>
|
69
|
+
</head>
|
70
|
+
<body>
|
71
|
+
|
72
|
+
<script type="text/javascript">
|
73
|
+
//Javascript変数定義
|
74
|
+
|
75
|
+
$(document).ready(function(){
|
76
|
+
var content =new Array();
|
77
|
+
$.ajax({
|
78
|
+
url: 'https://www.nikkei.com/news/jinji/hatsurei/',// http://から始まるURLを指定
|
79
|
+
type: 'GET',
|
80
|
+
success: function(res) {
|
81
|
+
$(res.responseText).find('.m-articleTitle_text_link').each(function(){
|
82
|
+
content.push($(this).attr('href'));
|
83
|
+
})
|
84
|
+
|
85
|
+
// console.log(content);
|
86
|
+
}
|
87
|
+
});
|
88
|
+
|
89
|
+
console.log('<a href="https://www.nikkei.com/'+content[0]+'"></a>');
|
90
|
+
});
|
91
|
+
|
92
|
+
</script>
|
93
|
+
</body>
|
94
|
+
</html>
|
95
|
+
```
|