问题
I have a popup.html that looks like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/fbh-ui.css" />
<script type="text/javascript" src="js/jq.js"></script>
<script type="text/javascript" src="js/fbh-popup.js"></script>
</head>
<body style="width: 200px">
<div id="fbh-main">
<div id="fbh-popup-enabled"></div>
</div>
</body>
And fbh-popup.js looks like this
$('#fbh-popup-enabled').html('test');
The JS should alter the content of the div but does not. I even tried a simple console.log('test') in the JS file and that didn't fire. I am at a loss.
回答1:
you have to write your code inside ready event callback
$(document).ready(function() {
$('#fbh-popup-enabled').html('test');
});
来源:https://stackoverflow.com/questions/14785101/chrome-extension-popup-js-is-not-working