Firstly sorry for the post, I'm pretty new to coding, I'll try and keep it short and sweet.
首先对这个帖子感到抱歉,我对编码很新,我会尽量保持简短和甜蜜。
Simply put, when I include my jQuery code inline, I.E. beneath my HTML, it works fine - the element I am trying to animate 'hides' and then 'shows' as it should.
简单地说,当我将我的jQuery代码包含在内联时,I.E。在我的HTML下面,它工作正常 - 我试图动画'隐藏'然后'显示'应该的元素。
However, when I make my own separate jquery.js file and put the code in there, it fails to render.
但是,当我创建自己单独的jquery.js文件并将代码放在那里时,它无法呈现。
I've got the cdn script from google and included that, alongside a script and src to where my file is located inside my project folder, but still no luck.
我有来自谷歌的cdn脚本,包括脚本和src以及我的文件位于我的项目文件夹中的位置,但仍然没有运气。
Inside my project folder I have a 'script.js' folder, and then within that a 'jquery.js' file.
在我的项目文件夹中,我有一个'script.js'文件夹,然后在'jquery.js'文件中。
Here's the code:
这是代码:
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="script.js/jquery.js"></script>
</head>
<div class="content">
<h2> Hi there</h2>
<h3> Take a look...</h3>
</div>
Here's the jQuery:
这是jQuery:
<script>
$(document).ready(function() {
$(".content").hide(1000).show(1000);
});
</script>
(Upon 'inspecting' the problem in chrome I get an error which says "jquery.js:1 Uncaught SyntaxError: Unexpected token <) - But I can't see where I am mis-using a '<'.
(在'检查'chrome中的问题时,我得到一个错误,上面写着“jquery.js:1 Uncaught SyntaxError:Unexpected token <) - 但是我看不出我错误地使用了'<'。
Thanks in advance, and please feel free to tell me if I have left out anything important.
在此先感谢,如果我遗漏了任何重要的内容,请随时告诉我。
2 个解决方案
#1
12
You need to remove the <script>
tags from your jquery.js file, those are HTML tags that are used for implementing inline JS, the error you are getting is because those tags are not valid JavaScript. Your JS file should just look like this:
您需要从jquery.js文件中删除
$(document).ready(function() {
$(".content").hide(1000).show(1000);
});
As far as folder naming, there's nothing wrong with having a period in your folder name, but as others have suggested it would probably be a good idea to remove the .js
part from your folder name even though it's not technically wrong and not what is causing your issue.
至于文件夹命名,在文件夹名称中有一个句点没有任何问题,但正如其他人所建议的那样,从文件夹名称中删除.js部分可能是一个好主意,即使它在技术上并不错,也不是什么导致你的问题。
#2
-5
Don't call your folder script.js, just call it "script".
不要调用你的文件夹script.js,只需将其称为“脚本”。
#1
12
You need to remove the <script>
tags from your jquery.js file, those are HTML tags that are used for implementing inline JS, the error you are getting is because those tags are not valid JavaScript. Your JS file should just look like this:
您需要从jquery.js文件中删除
$(document).ready(function() {
$(".content").hide(1000).show(1000);
});
As far as folder naming, there's nothing wrong with having a period in your folder name, but as others have suggested it would probably be a good idea to remove the .js
part from your folder name even though it's not technically wrong and not what is causing your issue.
至于文件夹命名,在文件夹名称中有一个句点没有任何问题,但正如其他人所建议的那样,从文件夹名称中删除.js部分可能是一个好主意,即使它在技术上并不错,也不是什么导致你的问题。
#2
-5
Don't call your folder script.js, just call it "script".
不要调用你的文件夹script.js,只需将其称为“脚本”。