所以我有一個Chrome擴展,但JavaScript沒有正確加載。我嘗試鏈接一個文件,但失敗慘敗。有什麼想法可以讓我點擊按鈕時運行功能? <腳本>標籤不要在此工作和按鈕什麼也不做,但最初的JavaScript並運行...這裏是我的代碼在Chrome擴展中正確鏈接JavaScript
manifest.json的(我覺得它工作正常):
{
"manifest_version": 2,
"name": "Getting started example",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}
popup.html(在JavaScript中的函數不鏈接到本):
<body style = "margin:10px">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="popup.js"></script>
<style>
//Fancy styles
large{font-size:30px}
span{}
.input-group{width:400px}
</style>
<!-- title -->
<large>
SpeedyURLs
</large>
<hr/>
<!-- Code that won't link with JavaScript -->
<div id = "stuff">
</div>
<div class = "input-group" id = "content"><input class = "form-control" placeholder = "Enter a URL here. Ex: https://www.google.com"/><span class="input-group-addon btn btn-default" style = "font-size:20px;width:50px;color:black" id="basic-addon1" onclick = "addNew()">+ </span></div>
<button onclick = 'document.write("HELLO")'>YAS</button>
</body>
popup.js(不鏈接功能):
function open(url){
window.open(url)}
function addNew(){
document.getElementById("stuff").innerHTML = document.getElementById("stuff").innerHTML+'<div class = "input-group" id = "content"><input class = "form-control" placeholder = "Enter a URL here. Ex: https://www.google.com"/><span style = "font-size:20px;width:50px;color:black" class="input-group-addon btn btn-danger" id="basic-addon1">x</span></div>'}
icon.png(默認圖片沒有代碼,工作正常)
所以,JS中的函數不會鏈接到HTML。有任何想法嗎?
([Chrome擴展程序無法正常工作範圍內的onClick]的可能的複製http://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-working) –