Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
获取呼叫者';jquery插件中的s id_Jquery_Jquery Plugins - Fatal编程技术网

获取呼叫者';jquery插件中的s id

获取呼叫者';jquery插件中的s id,jquery,jquery-plugins,Jquery,Jquery Plugins,我在jquery方面有一些经验,但现在正在学习插件创建。我在html页面中使用了以下javascript $("#testid").myplugin({}); 在JQuery插件中,我有以下代码: (function( $ ) { $.fn.siddeffect = function (options) { console.log(this.attr('id')); console.log($(this).attr('id')); ret

我在jquery方面有一些经验,但现在正在学习插件创建。我在html页面中使用了以下javascript

$("#testid").myplugin({});
在JQuery插件中,我有以下代码:

(function( $ ) {
    $.fn.siddeffect = function (options) {
        console.log(this.attr('id'));
        console.log($(this).attr('id'));
        return this;
    };
})( jQuery );
我在控制台中得到了跟踪

undefined
undefined
我也尝试了一些其他的组合,但没有得到id(在上面的例子中是testid)。有没有办法在插件中获取调用id/选择器

PS:以html格式存在,作为正文中唯一的元素。我认为

$("#testid").myplugin({});
应该是

$("#testid").siddeffect({});

$.fn.siddeffect
应更改为
$.fn.myplugin

我想你的原始文件有打字错误。 你的代码运行得很好

我想

$("#testid").myplugin({});
应该是

$("#testid").siddeffect({});

$.fn.siddeffect
应更改为
$.fn.myplugin

我想你的原始文件有打字错误。
你的代码运行得很好

除了调用“myplugin”而不是“SIDDEFECT”之外,您的代码看起来不错。无论如何,它在这里工作得很好:


干杯

除了调用“myplugin”而不是“siddeffect”之外,您的代码看起来不错。无论如何,它在这里工作得很好:


干杯

这有什么价值?它是你期望的吗?什么是
myplugin
?因为如果调用
$(“#testid”).siddeffect({})它将显示
testid
。只需快速键入编辑。$。fn.siddeffect实际上是$.fn.myplugin。所以myplugin是插件的名称,也是插件JSOk中的函数。在这种情况下,您没有任何问题。这个值是多少?它是你期望的吗?什么是
myplugin
?因为如果调用
$(“#testid”).siddeffect({})它将显示
testid
。只需快速键入编辑。$。fn.siddeffect实际上是$.fn.myplugin。所以myplugin是插件的名称,也是插件JSOk中的函数。在本例中,您并没有任何问题。谢谢,有输入错误+1寻求帮助和快速回复。谢谢,有打字错误+1寻求帮助和快速回复。谢谢,有打字错误+1寻求帮助和快速回复。谢谢,有打字错误+1寻求帮助和快速回复。