我无法让我的jQuery工作在最简单的水平 [英] I'm having trouble getting my jQuery to work on the simplest level
问题描述
好的,这是一个总的noob问题。我试图使用HTML,CSS和JavaScript从头开始构建一个网站,我想使用jQuery。由于某种原因,我可以得到HTML和CSS工作,但我不能在我的 script.js
文件中使用jQuery。我已下载jQuery:
Ok, so this is a total noob question. I'm trying to build a site from scratch using HTML, CSS, and JavaScript and I want to use jQuery. For some reason I can get the HTML and CSS working but I can't use jQuery in my script.js
file. I've downloaded jQuery:
< img src =https://i.stack.imgur.com/FBK4C.pngalt =enter image description here>
和我用< script>
标签链接到它,但是当我尝试使用我构建的时候,没有任何反应。
And I've linked to it with a <script>
tag, but when I try to use what I've built, nothing happens.
我的HTML:
<!DOCTYPE html>
<html>
<head>
<title>Freeflow Academy</title>
<link rel='stylesheet' type='stylesheet' href='stylesheet.css'>
<link rel='stylesheet' type='stylesheet' href='http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css' />
<script type='text/javascript' src='script.js'></script>
<script type='text/javascript' src="jquery-2.2.0.min.js"></script>
</head>
<body>
<p>This is a test</p>
</body>
</html>
我的CSS:
p {
background-color: blue;
}
我使用jQuery的JavaScript:
My JavaScript with jQuery:
$(document).ready(function(){
$('p').on('click', function(){
$(this).css('background-color','red');
});
});
所有我想要做的是获取背景颜色,任何帮助是赞赏。我认为问题与我的< script>
或< link>
标签有关,
All I'm trying to do is get the background color to change on a click. Any help is appreciated. I think the problem has to do with my <script>
or <link>
tags, but I'm not sure which.
推荐答案
首先加载jQuery,然后是自定义脚本
First load jQuery, then your custom script
<script type='text/javascript' src="jquery-2.2.0.min.js"></script>
<script type='text/javascript' src='script.js'></script>
加载优先级是从上到下,如果jQuery在脚本加载之前没有加载, t工作。
The loading priority is from top to bottom, if jQuery is not loaded before script loads, it won't work.
这篇关于我无法让我的jQuery工作在最简单的水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!