我从 Codeacademy jQuery ex 复制/粘贴了代码。 4、“什么是 jQuery?”,将其转换为我笔记本电脑上相同的 html、css 和 javascript 文件。然后我将其推送到我的 github.io; jQuery 代码似乎无法在我的 Firefox 浏览器(Ubuntu 规范版本 26 - 1.0)中工作。该代码肯定可以在 Codeacademy 屏幕上运行。
这是index.html:
<!DOCTYPE html>
<html>
<head>
<title>What Say You?</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="ready">I'm ready!</div>
<div id="notready">You'll never take me alive, jQuery!</div>
</body>
</html>
这是 stylesheet.css
div {
height:100px;
width:100px;
border-radius:5px;
display: inline-block;
text-align: center;
vertical-align: middle;
font-family: Verdana, Arial, Sans-Serif;
margin-right:5px;
}
#ready {
background-color:#008800;
color:#FFFFFF;
}
#notready {
background-color:#FF0000;
color:#FFFFFF;
}
这是 script.js:
$(document).ready(function() {
$('#notready').fadeOut(1000);
});
页面在这里:http://bonza-times.github.io/
如何让这段代码在 Firefox 中正常工作?谢谢!
最佳答案
在 codeacademy 中,jquery 是隐式加载的,但如果您希望将其放在独立页面上,则需要将其手动包含在 <head>
中。
使用像这样的 CDN:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
或者将其下载到您的元素中并添加
<script src="path/to/your/js/jquery.js"></script>
关于javascript - 当通过 github.io 部署时,jQuery 在 Codeacademy 上可以运行,但在 Firefox 中则不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21217291/