I built a random sentence generator -- when you click an HTML button, a random sentence is generated beneath it. The generation is powered by a simple script and jQuery.
It works fine on my local machine: When I open index.html in a browser, everything goes smoothly.
But once I upload to GiHub and visit the GitHub pages URL, the generator stops working. Clicking the button does nothing.
Here's the script (it's all contained within the index.html file):
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
and
<script> function sentenceLoad() {
//declare arrays
var nouns = ['Mulder, Scully, and'];
var names = ['Assistant Director Skinner', 'the Cigarette Smoking Man', 'Alex Krycek'];
var actions = ['are running from alien bounty hunters', 'are tracking a shapeshifter', 'are hunting a mutant serial killer'];
var places = ['in the woods of New Jersey', 'in a government bunker', 'in Olympic National Forest'];
//shuffle through contents of each array, picking one entry per array
var randNoun = nouns[Math.floor(Math.random() * nouns.length)];
var randName = names[Math.floor(Math.random() * names.length)];
var randAction = actions[Math.floor(Math.random() * actions.length)];
var randPlace = places[Math.floor(Math.random() * places.length)];
//place the random entry into the appropriate place in the HTML
jQuery("h5").html("");
jQuery("h5").append(randNoun + " ");
jQuery("h5").append(randName + " ");
jQuery("h5").append(randAction + " ");
jQuery("h5").append(randPlace);
}
What would cause this to work locally, but not work on Github Pages?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…