4

我是一个完整的新手,我想从“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;

});

清单.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"
  }
}
4

1 回答 1

7

使用此 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>
于 2013-09-25T19:46:12.243 回答