gpt4 book ai didi

javascript - Chrome 扩展更改 popup.html 文本

转载 作者:太空宇宙 更新时间:2023-11-04 14:18:30 25 4
gpt4 key购买 nike

我是一个完全的新手,我想从“p”标签中取出一段文本并将其放入另一个“p”标签中,这样当我点击我的扩展时,我会看到显示的两个文本。我做错了什么?以及我以后如何避免类似的错误?

弹出窗口:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" scr= "popup.js"></script>
</head>
<body>
<p id="firstText">this is the text to be repeated</p>
<p id= "secondText"></p>
</body>
</html>

弹出.js:

document.addEventListener('DOMContentLoaded', function () {

var test= document.getElementById("firstText").innerHTML;
document.getElementById("secondText").innerHTML=test;

});

list .json:

{
"manifest_version": 2,
"name": "test",
"description": "useless",
"version": "1.0",
"background": {
"scripts": [ "popup.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["popup.js"]
}
],
"permissions": [
"activeTab","tabs", "http://*/*"
],
"browser_action": {
"default_popup": "popup.html"
}
}

最佳答案

将此 HTML 用于弹出窗口:您输入错误 src

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src= "popup.js"></script>
</head>
<body>
<p id="firstText">this is the text to be repeated</p>
<p id= "secondText"></p>
</body>
</html>

关于javascript - Chrome 扩展更改 popup.html 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19007860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com