我在 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/selector 吗?
PS:存在于 html 中,作为正文中的唯一元素。