回答編集履歴

2

調整

2019/01/24 03:50

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -8,25 +8,25 @@
8
8
 
9
9
  var arrImage = [
10
10
 
11
- {src:"img/00.png",href:"0.href",sort:Math.random(),},
11
+ {src:"img/00.png",href:"0.html",sort:Math.random(),},
12
12
 
13
- {src:"img/01.png",href:"1.href",sort:Math.random(),},
13
+ {src:"img/01.png",href:"1.html",sort:Math.random(),},
14
14
 
15
- {src:"img/02.png",href:"2.href",sort:Math.random(),},
15
+ {src:"img/02.png",href:"2.html",sort:Math.random(),},
16
16
 
17
- {src:"img/03.png",href:"3.href",sort:Math.random(),},
17
+ {src:"img/03.png",href:"3.html",sort:Math.random(),},
18
18
 
19
- {src:"img/04.png",href:"4.href",sort:Math.random(),},
19
+ {src:"img/04.png",href:"4.html",sort:Math.random(),},
20
20
 
21
- {src:"img/05.png",href:"5.href",sort:Math.random(),},
21
+ {src:"img/05.png",href:"5.html",sort:Math.random(),},
22
22
 
23
- {src:"img/06.png",href:"6.href",sort:Math.random(),},
23
+ {src:"img/06.png",href:"6.html",sort:Math.random(),},
24
24
 
25
- {src:"img/07.png",href:"7.href",sort:Math.random(),},
25
+ {src:"img/07.png",href:"7.html",sort:Math.random(),},
26
26
 
27
- {src:"img/08.png",href:"8.href",sort:Math.random(),},
27
+ {src:"img/08.png",href:"8.html",sort:Math.random(),},
28
28
 
29
- {src:"img/09.png",href:"9.href",sort:Math.random(),},
29
+ {src:"img/09.png",href:"9.html",sort:Math.random(),},
30
30
 
31
31
  ];
32
32
 
@@ -45,3 +45,71 @@
45
45
  </script>
46
46
 
47
47
  ```
48
+
49
+
50
+
51
+ # 組み込み
52
+
53
+ ```javascript
54
+
55
+ <script>
56
+
57
+ window.addEventListener('DOMContentLoaded', function(e){
58
+
59
+ var arrImage = [
60
+
61
+ {src:"img/00.png",href:"0.html",sort:Math.random(),},
62
+
63
+ {src:"img/01.png",href:"1.html",sort:Math.random(),},
64
+
65
+ {src:"img/02.png",href:"2.html",sort:Math.random(),},
66
+
67
+ {src:"img/03.png",href:"3.html",sort:Math.random(),},
68
+
69
+ {src:"img/04.png",href:"4.html",sort:Math.random(),},
70
+
71
+ {src:"img/05.png",href:"5.html",sort:Math.random(),},
72
+
73
+ {src:"img/06.png",href:"6.html",sort:Math.random(),},
74
+
75
+ {src:"img/07.png",href:"7.html",sort:Math.random(),},
76
+
77
+ {src:"img/08.png",href:"8.html",sort:Math.random(),},
78
+
79
+ {src:"img/09.png",href:"9.html",sort:Math.random(),},
80
+
81
+ ];
82
+
83
+ arrImage.sort(function(x,y){
84
+
85
+ return x.sort-y.sort;
86
+
87
+ });
88
+
89
+ [].forEach.call(document.querySelectorAll('.link_list li'),function(x,y){
90
+
91
+ x.querySelector('a').setAttribute("href",arrImage[y].href);
92
+
93
+ x.querySelector('img').setAttribute("src",arrImage[y].src);
94
+
95
+ x.querySelector('img').setAttribute("alt",arrImage[y].src);
96
+
97
+ });
98
+
99
+ });
100
+
101
+
102
+
103
+ </script>
104
+
105
+ <ul class="link_list">
106
+
107
+ <li><a href="01.html" id="link1"><img name="imgNumber1" src="img/01.png" alt="" width="160" height="255" border="0"></a></li>
108
+
109
+ <li><a href="02.html" id="link2"><img name="imgNumber2" src="img/02.png" alt="" width="160" height="255" border="0"></a></li>
110
+
111
+ <li><a href="03.html" id="link3"><img name="imgNumber3" src="img/03.png" alt="" width="160" height="255" border="0"></a></li>
112
+
113
+ </ul>
114
+
115
+ ```

1

chousei

2019/01/24 03:50

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -8,25 +8,25 @@
8
8
 
9
9
  var arrImage = [
10
10
 
11
- {src:"img/00.png",html:"0.html",sort:Math.random(),},
11
+ {src:"img/00.png",href:"0.href",sort:Math.random(),},
12
12
 
13
- {src:"img/01.png",html:"1.html",sort:Math.random(),},
13
+ {src:"img/01.png",href:"1.href",sort:Math.random(),},
14
14
 
15
- {src:"img/02.png",html:"2.html",sort:Math.random(),},
15
+ {src:"img/02.png",href:"2.href",sort:Math.random(),},
16
16
 
17
- {src:"img/03.png",html:"3.html",sort:Math.random(),},
17
+ {src:"img/03.png",href:"3.href",sort:Math.random(),},
18
18
 
19
- {src:"img/04.png",html:"4.html",sort:Math.random(),},
19
+ {src:"img/04.png",href:"4.href",sort:Math.random(),},
20
20
 
21
- {src:"img/05.png",html:"5.html",sort:Math.random(),},
21
+ {src:"img/05.png",href:"5.href",sort:Math.random(),},
22
22
 
23
- {src:"img/06.png",html:"6.html",sort:Math.random(),},
23
+ {src:"img/06.png",href:"6.href",sort:Math.random(),},
24
24
 
25
- {src:"img/07.png",html:"7.html",sort:Math.random(),},
25
+ {src:"img/07.png",href:"7.href",sort:Math.random(),},
26
26
 
27
- {src:"img/08.png",html:"8.html",sort:Math.random(),},
27
+ {src:"img/08.png",href:"8.href",sort:Math.random(),},
28
28
 
29
- {src:"img/09.png",html:"9.html",sort:Math.random(),},
29
+ {src:"img/09.png",href:"9.href",sort:Math.random(),},
30
30
 
31
31
  ];
32
32