4

私は完全な初心者です。「p」タグからテキストを取得し、別の「p」タグに入れたいので、拡張機能をクリックすると、2 つのテキストが表示されます。私が間違っているのは何ですか?また、今後同様の間違いを避けるにはどうすればよいですか?

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 に答える