我是一个完整的新手,我想从“p”标签中取出一个文本并将其放在另一个“p”标签中,这样当我点击我的扩展名时,我会看到正在显示的两个文本。 我做错了什么?我怎样才能避免将来出现类似的错误?
popup.html:
<!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>
popup.js:
document.addEventListener('DOMContentLoaded', function () {
var test= document.getElementById("firstText").innerHTML;
document.getElementById("secondText").innerHTML=test;
});
manifest.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"
}
}
答案 0 :(得分:6)
使用此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>