2013-09-25 53 views
2

我是一個完全新手,我想從「p」標記中取文本並將其放在另一個「p」標記中,因此當我點擊我的分機時,我看到兩個文本正在顯示。 我做錯了什麼?我怎樣才能避免將來出現類似的錯誤?Chrome擴展程序正在更改popup.html文本

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" 
    } 
} 
+6

如果這是一個確切的複製/粘貼,您在''中有一個拼寫錯誤。它應該讀取'src'而不是'scr'。 –

+0

@ChrisP我很尷尬,非常感謝你的幫助! – Apastrix

回答

4

使用此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> 
+0

我使用sublimetext2,我沒有看到,我花了24年搜索互聯網和更改代碼,我甚至嘗試jQuery的功能,試圖在Js ^^之前加載DOM「真的很感謝你!我沒有足夠的聲望投票給你,但我會回覆它承諾=) – Apastrix

相關問題