Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.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 理解plugin-$/jQuery的概念没有定义_Javascript_Jquery_Plugins_Jquery Plugins - Fatal编程技术网

Javascript 理解plugin-$/jQuery的概念没有定义

Javascript 理解plugin-$/jQuery的概念没有定义,javascript,jquery,plugins,jquery-plugins,Javascript,Jquery,Plugins,Jquery Plugins,我用以下语法编写了一个插件: (function($){ $.fn.samplePlugin = function() { return this.each(function() { //My logic here }); }; })(jQuery); 然后,我叫了一个新来的 $(document).ready(function(){ $('#sample').samplePlugin(); }); 现在我的控制台中有两个错误: ReferenceErr

我用以下语法编写了一个插件:

(function($){
 $.fn.samplePlugin = function() {
    return this.each(function() {
    //My logic here
    });
 };
})(jQuery);
然后,我叫了一个新来的

 $(document).ready(function(){
    $('#sample').samplePlugin();
});
现在我的控制台中有两个错误:

ReferenceError: jQuery is not defined
ReferenceError: $ is not defined
你能告诉我我遗漏了什么吗?当你创建或包含插件时,$annotation的使用流程应该是什么


谢谢,

在插件之前包含jQuery。

在插件之前包含jQuery。

(1)检查是否正确包含jQuery库。在调用插件之前,请先输入代码。 (2) 如果您在chrome上验证是否下载了jquery文件,请打开开发者工具[windows中的快捷键F12]并切换到“资源”选项卡。查看是否在页面资源中的脚本下下载了jquery文件。

(1)检查是否正确包含了jquery库。在调用插件之前,请先输入代码。
(2) 如果您在chrome上验证是否下载了jquery文件,请打开开发者工具[windows中的快捷键F12]并切换到“资源”选项卡。查看是否在页面资源中的脚本下下载了jquery文件。

请确保正确加载了jquery文件


如果您使用的是jQuery UI库,请确保顺序正确。首先需要包含jQuery库的引用,然后包括jQuery UI库

write确保jquery文件已正确加载


如果您使用的是jQuery UI库,请确保顺序正确。首先需要包括jQuery库的引用,然后是jQuery UI库

您是否在函数上方包含jQuery

如果是,则使用

$=jQuery.noConflict()


调用您的函数。

您是否在函数上方包含jQuery

var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

jq.onload = procede;//make sure you don't type parenthesis

//i.e. 'procede()' runs function instantly
//     'procede' gives it a function to run when it's ready

...

function procede()
{
//jQuery commands are loaded (do your magic)


}
如果是,则使用

$=jQuery.noConflict()


调用函数。

然后,尝试脚本开头的
alert(jQuery)
检查jQuery是否正确加载。谢谢,这很有帮助。我包含了google托管的jquery库,因此路径不正确。然后,在脚本开头尝试
alert(jquery)
检查jquery是否正确加载。谢谢,这很有帮助。我包括了谷歌托管的jquery库,所以路径不正确。拼写错误,不应该是noConflict@JatinDhoot:那么它应该是什么呢?拼写是错误的Sandeep,它不应该是错误的noConflict@JatinDhoot:那么它应该是什么呢?
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

jq.onload = procede;//make sure you don't type parenthesis

//i.e. 'procede()' runs function instantly
//     'procede' gives it a function to run when it's ready

...

function procede()
{
//jQuery commands are loaded (do your magic)


}