回答編集履歴

1

修正

2018/08/10 07:28

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -31,3 +31,47 @@
31
31
  <span id="sp"></span>
32
32
 
33
33
  ```
34
+
35
+
36
+
37
+ # 文字列指定
38
+
39
+ ```javascript
40
+
41
+ <script>
42
+
43
+ window.addEventListener('DOMContentLoaded', function(e){
44
+
45
+ document.querySelector('#btn').addEventListener('click',function(e){
46
+
47
+ var arr =[
48
+
49
+ ['1.jpg', '2.jpg', '3.jpg'],
50
+
51
+ ['1文字列', '2文字列', '3文字列'],
52
+
53
+ ];
54
+
55
+ var a = Math.floor(Math.random() * arr[0].length);
56
+
57
+ document.querySelector("#im").setAttribute("src",arr[0][a]);
58
+
59
+ document.querySelector("#im").addEventListener('click',function(e){
60
+
61
+ document.querySelector("#sp").textContent=arr[1][a];
62
+
63
+ });
64
+
65
+ });
66
+
67
+ });
68
+
69
+ </script>
70
+
71
+ <input type="button" value="Push" id="btn">
72
+
73
+ <img id="im" alt="image is here">
74
+
75
+ <span id="sp"></span>
76
+
77
+ ```