Hi I'm trying to pull some javascript on a page off of the page and putting it into an external javascript file for reusability.
Just as a test I'm just t开发者_如何学Pythonrying to display an alert text box but even that's not working.
Here's what I have so far.
Page with the javascript
EDIT: Ignore the type="text/javascript" that wasn't the problem
Here's the actual content of the script.js
File Structure from the site root
Honestly it looks like it should work but whenever I run the page in the browser I'm getting this error.
I know that the path is correct, but what am I missing?
The problem was I wasn't clearing my cache, sorry newbie mistake :(
Looks like some simple javascript syntax errors; missing semicolons. You can use JSLint to find those. This should work (Assuming that jQuery is loading before your other two scripts):
Your 'script.js':
var projectApi = function() {};
projectApi.prototype.HelloWorld = function() {
alert('Hello World');
};
Your page javascript:
$(document).ready(function() {
var api = new projectApi();
api.HelloWorld();
});
精彩评论