こちらのコードですが、CodePen上では動作するのですが、
CodePen上で動作している様子
ローカル環境のLive Server上、もしくはhtmlを直接開いても正常に動作しません。ローカルで動かしたいのですが、何が問題で動かないのかわかりません。
HTML
1forEachCallBack.html 2 3<!DOCTYPE html> 4<html lang="ja"> 5<head> 6 <meta charset="UTF-8"> 7 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 8 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 9 <title>Document</title> 10</head> 11<body> 12 <div id="show"></div> 13 <script scr="forEachCallBack.js"></script> 14</body> 15</html>
JavaScript
1forEachCallBack.js 2 3const printElement = (currentValue, index, array) => { 4 document.getElementById("show").innerHTML += `${index + 1}個目の値: ${currentValue} <br>`; 5 console.log((index + 1) + "個目の値: " + currentValue); 6}; 7 8const list = [2, 7, 66, 9]; 9list.forEach(printElement);
VS CodeのLive ServerをChromeで開いた時ののエラーメッセージ
Error handling response: TypeError: Cannot read properties of undefined (reading 'blocks')
at chrome-extension://comoodengbhchaeglcgaaokhaicgngoo/src/cs/app.js:1:357
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
forEachCallBack.htmlをChromeでじかに開くとエラーは出ません。
アドバイスのほど何卒宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/26 19:50