Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中嵌入jquery库?_Javascript_Jquery - Fatal编程技术网

如何在javascript中嵌入jquery库?

如何在javascript中嵌入jquery库?,javascript,jquery,Javascript,Jquery,我在jQuery.xyz.js中有一个jQuery库代码。 我有一个html文件,它以这种方式使用jquery.xyz.js中定义的函数 <html> <body> <script type="text/javascript"> document.write("This is my first JavaScript!"); $(function(){ $("ul#xy01").xyz(); }); </script> </body>

我在jQuery.xyz.js中有一个jQuery库代码。 我有一个html文件,它以这种方式使用jquery.xyz.js中定义的函数

<html>
<body>

<script type="text/javascript">
document.write("This is my first JavaScript!");
$(function(){ $("ul#xy01").xyz(); }); 
</script>

</body>
</html> 

编写(“这是我的第一个JavaScript!”);
$(function(){$(“ul#xy01”).xyz();});

但是jQuery没有运行,我假设这是因为我没有将jQuery正确加载到html页面上。那么我该怎么做呢?

在使用脚本文件中定义的函数之前,只需包含脚本文件(
$
只是一个函数),例如:

<html>
<body>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="jquery.xyz.js"></script>
  <script type="text/javascript">
    $(function(){ $("ul#xy01").xyz(); }); 
  </script>
</body>
</html> 

$(function(){$(“ul#xy01”).xyz();});

确保在依赖jQuery的插件之前包含jQuery,否则首先会出现一些错误。

在使用脚本文件中定义的函数之前,只需包含脚本文件(
$
只是一个函数),例如:

<html>
<body>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="jquery.xyz.js"></script>
  <script type="text/javascript">
    $(function(){ $("ul#xy01").xyz(); }); 
  </script>
</body>
</html> 
 <script type="text/javascript" src="jquery.js"></script>

$(function(){$(“ul#xy01”).xyz();});
确保在依赖jQuery的插件之前包含jQuery,否则首先会出现一些错误。


 <script type="text/javascript" src="jquery.js"></script>
有关基本信息,请参阅手册中的,以及获取库(或查找内容交付网络上直接链接的地址)的步骤。


有关基本信息,请参阅手册中的,以及获取库(或查找内容交付网络上直接链接的地址)的步骤。


在jQuery代码上方的


在jQuery代码上方的




编写(“这是我的第一个JavaScript!”);
$(function(){$(“ul#xy01”).xyz();});

编写(“这是我的第一个JavaScript!”);
$(function(){$(“ul#xy01”).xyz();});

var script=document.createElement('script');
script.onload=函数(){
//用脚本做一些事情
};
script.src=https://ajax.googleapis.com/ajax/libs/jquery/xx.xx/jquery.min.js';
document.head.appendChild(脚本);

var script=document.createElement('script');
script.onload=函数(){
//用脚本做一些事情
};
script.src=https://ajax.googleapis.com/ajax/libs/jquery/xx.xx/jquery.min.js';
document.head.appendChild(脚本);
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js">   
</script>
</head>
<body>

<script type="text/javascript">
document.write("This is my first JavaScript!");
$(function(){ $("ul#xy01").xyz(); }); 
</script>

</body>
</html> 
<script>

var script = document.createElement('script');
script.onload = function () {
 //do stuff with the script

};
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/xx.xx/jquery.min.js';
document.head.appendChild(script);

</script>