Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

javascript - 如何将JavaScript文件链接到HTML文件?(How do I link a JavaScript file to a HTML file?)

How do you properly link a JavaScript file to a HTML document?

(如何正确地将JavaScript文件链接到HTML文档?)

Secondly, how do you use jQuery within a JavaScript file?

(其次,如何在JavaScript文件中使用jQuery?)

  ask by firstofth300 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First you need to download JQuery library from http://jquery.com/ then load the jquery library the following way within your html head tags

(首先,您需要从http://jquery.com/下载JQuery库,然后在html head标签中按以下方式加载jquery库)

then you can test whether the jquery is working by coding your jquery code after the jquery loading script

(那么你可以通过在jquery加载脚本之后编写你的jquery代码来测试jquery是否正常工作)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--LINK JQUERY-->
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<!--PERSONAL SCRIPT JavaScript-->
<script type="text/javascript">
   $(function(){
      alert("My First Jquery Test");
   });
</script>

</head>
<body><!-- Your web--></body>
</html>

If you want to use your jquery scripts file seperately you must define the external .js file this way after the jquery library loading.

(如果要单独使用jquery脚本文件,则必须在加载jquery库之后以这种方式定义外部.js文件。)

<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script src="js/YourExternalJQueryScripts.js"></script>

Test in real time(实时测试)

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!--LINK JQUERY--> <script type="text/javascript" src="jquery-3.3.1.js"></script> <!--PERSONAL SCRIPT JavaScript--> <script type="text/javascript"> $(function(){ alert("My First Jquery Test"); }); </script> </head> <body><!-- Your web--></body> </html> 


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...