我還閱讀了有關同一型別的其他一些問題,但它不起作用。我正在嘗試將<p>標簽內的文本更改為 Hello world。它在 localhost 但不是 chrome 擴展。
我的清單.json
{
"name": "Azura",
"description": "Yes.! Azura",
"version": "1.0",
"manifest_version": 3,
"permissions": ["tts"],
"action": {
"default_popup": "index.html"
}
}
我的 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./styles/css/style.css" />
<title>Azura</title>
</head>
<body>
<div class="container">
<div>
<h1 id="">Welcome</h1>
</div>
<div class="formHolder">
<form>
<label for="fname">Search</label><br />
<input type="text" id="imgAddress" /><br />
<div onclick="myFunction()" id="submit">Submit</div>
</form>
</div>
<p class="socials">socials here</p>
<div class="powered">Powered by Azure - cognitive services</div>
</div>
<p id="textp">asdsad</p>
</body>
<script src="./backend/azureCognitive.js"></script>
<script src="./backend/main.js"></script>
</html>
我的 main.js
var submitBtn = document.getElementById("submit");
submitBtn.addEventListener(onclick, myFunction);
function myFunction() {
document.getElementById("textp").innerText = "Hello world";
var input = document.getElementById("imgAddress");
// console.log(input.value);
}
所有這些在 localhost 上運行良好,但在 chrome 擴展上運行不佳。任何幫助將不勝感激 :)
uj5u.com熱心網友回復:
我認為你的代碼是錯誤的。事件監聽器應該是這樣的。
submitBtn.addEventListener('click', myFunction)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/428340.html
標籤:javascript 谷歌浏览器
上一篇:Selenium不適用于某個網站
下一篇:僅選擇xpath串列中的元素
