在js文件中使用jQuery [英] using jQuery in a js file
问题描述
通过include < code>< script type =text / javascriptsrc =scripts / jquery-1.10.2.js>< / script>
在HTML文件中,我可以直接在这个文件中写入jQuery。但是,我没有在单个文件上工作,因此,html中太多的js代码看起来不太好。 js文件中可以使用jQuery吗?所以我可以在一个独立的js文件中加入一些常用的功能。
您的js文件应该像下面这样开始: main.js strong>
$(document).ready(function(){
// code here
} );
请注意,你可以使用 $(document).load(function()太
在你的 index.html 中将这个放在页脚中: index.html
<!DOCTYPE HTML>
< html>
< head> ;
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title>您的网站< / title>
< / head>
< body>
<! - ============ MAIN-CONTAINER ======== ==== - >
< section>
< / section>
<! - ============ SIDEBAR =================== - >
< aside>
< / aside>
<! - ============ FOOTER ==================== - >
< footer>
<< b< ; script src =http://code.jquery.com/jquery-2.0.0.min.js>< / script>
<脚本SRC = JS / main.js >< /脚本>
< / footer>
< / body>
< / html>
获得最佳表现。
<如果你想使用它作为
< script src =scripts / strong> alfernative 的jquery-2.0.0.min.js>< /脚本>
下载:
http://code.jquery.com/jquery-2.0.0.min.js
并将其放入名为脚本的新文件夹中并替换
在您的页脚中是这样的: I know by include create a folder with the name js and inside put your js file for example main.js your js file should start like : main.js note that you can use $(document).load(function() too In your index.html put this in the footer like this : index.html for the best performance. alfernative
if you want to use it as download this: http://code.jquery.com/jquery-2.0.0.min.js and put it into a new folder with the name scripts and replace with in your footer like this:
这篇关于在js文件中使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!< script src =http://code.jquery.com/jquery-2.0.0.min.js>< / script> $
$ b
< script src =脚本/ jQuery的2.0.0.min.js>< /脚本>
< footer>
< script src =scripts / jquery-2.0.0.min.js>< / script>
< script src =js / main.js>< / script>
< / footer>
<script type="text/javascript" src="scripts/jquery-1.10.2.js"></script>
in HTML file, I can write in jQuery in this file directly. However, I am not working on a single file, thus, too much js code in the html doesn't look good. Can there be some method to use jQuery in js file? So I can put some common function in a standalone js file.$(document).ready(function(){
//code here
});
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>
</head>
<body>
<!--============MAIN-CONTAINER============ -->
<section>
</section>
<!--============SIDEBAR=================== -->
<aside>
</aside>
<!--============FOOTER==================== -->
<footer>
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script src="js/main.js"></script>
</footer>
</body>
</html>
<script src="scripts/jquery-2.0.0.min.js"></script>
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script src="scripts/jquery-2.0.0.min.js"></script>
<footer>
<script src="scripts/jquery-2.0.0.min.js"></script>
<script src="js/main.js"></script>
</footer>