質問編集履歴

1

2つ補足しました

2019/12/28 13:19

投稿

ogyougi
ogyougi

スコア60

test CHANGED
File without changes
test CHANGED
@@ -89,3 +89,143 @@
89
89
 
90
90
 
91
91
  エラーも出ないためにこの再現条件を見つけるのに本当に苦労しましたので、明らかにデメリットを大きく感じております。
92
+
93
+
94
+
95
+ ###補足(ブラウザによる違い)
96
+
97
+ ご報告です。エラーがでずファイルの読み込みもないのはFirefoxでの場合だけでして、Chromeでは下記エラーが無事出ました。
98
+
99
+ ```
100
+
101
+ test.js:7 Uncaught SyntaxError: Identifier 'item' has already been declared
102
+
103
+ ```
104
+
105
+ ###補足(全ファイル)
106
+
107
+ 全てのファイルの【ディレクトリ】と【中身】は下記です。(親テーマでも一緒ですがわかりやすいので子テーマにします)
108
+
109
+
110
+
111
+ プラグイン等が無いまっさらなWordPress(最新の5.0.3)に入れて、Firefoxでお試しいただければ再現するかと思います。
112
+
113
+
114
+
115
+ 【ディレクトリ】
116
+
117
+ ```
118
+
119
+ twentynineteen-child
120
+
121
+ ├ functions.php
122
+
123
+ ├ style.css
124
+
125
+ ├ js
126
+
127
+  ├ test.js
128
+
129
+  ├ ok.js
130
+
131
+ ```
132
+
133
+ 【中身】
134
+
135
+
136
+
137
+ 「functions.php」
138
+
139
+ ```php
140
+
141
+ <?php
142
+
143
+ add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
144
+
145
+ function theme_enqueue_styles() {
146
+
147
+ wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
148
+
149
+
150
+
151
+ }
152
+
153
+
154
+
155
+ add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
156
+
157
+ function my_enqueue_scripts(){
158
+
159
+
160
+
161
+ $template_directory_uri = 'http://example.com/wp-content/themes/twentynineteen-child';
162
+
163
+
164
+
165
+ // 読み込まれる
166
+
167
+ wp_enqueue_script( 'ok.js', $template_directory_uri . '/js/ok.js', array(), '1.0.0', true );
168
+
169
+
170
+
171
+ // 読み込まれない
172
+
173
+ wp_enqueue_script( 'test.js', $template_directory_uri . '/js/test.js', array(), '1.0.0', true );
174
+
175
+
176
+
177
+ }
178
+
179
+ ```
180
+
181
+ 「style.css」
182
+
183
+ ```css
184
+
185
+ /*
186
+
187
+ Theme Name: twentynineteen child
188
+
189
+ Template: twentynineteen
190
+
191
+ */
192
+
193
+ ```
194
+
195
+ 「test.js」
196
+
197
+ ```js
198
+
199
+ (function($){
200
+
201
+
202
+
203
+ $(document).on('click','.button', function(e){
204
+
205
+
206
+
207
+ const item = $(this).closest('.item');
208
+
209
+
210
+
211
+ const item = $(this).closest('.item');
212
+
213
+
214
+
215
+ });
216
+
217
+
218
+
219
+
220
+
221
+ })(jQuery);
222
+
223
+ ```
224
+
225
+ 「ok.js」
226
+
227
+ ```js
228
+
229
+ console.log('this is ok.js');
230
+
231
+ ```