Jquery Options using $(this)
Jquery Options using $(this)
我正在尝试编写一个jquery插件,我对著名的"this"有一个问题。
这是自定义插件的调用:
$('.selector').myPlugin({
test: $(this).attr('rel')
});
现在,在我的插件中的某个地方:
$.myPlugin = function (options) {
alert(options.test);
}
我的问题是:如何使用 $(this( 在插件中使用我的选择器的 Rel 属性?
前面的代码总是告诉我"this"是文档。
非常感谢
$(this)
不是您希望它在该对象文本中的样子。循环使用each
:
$('.selector').each(function() {
$(this).myPlugin({
test: $(this).attr('rel')
});
});
在 each
中,this
将指向正确的元素,而不是调用函数的上下文。
相关文章:
- $(this).prop('property') vs. this.property
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 在另一个函数中使用变量this
- this.router在AngularJS 2中未定义
- reactjs this.refs vs document.getElementById
- JavaScript 中的嵌套函数和 “this” 关键字
- React+Meteor:this.ops返回未定义
- javascript中对象构造函数中的var属性与this.properties
- 函数中this和var之间的区别
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- Understanding Javascript scope with "var that = this&qu
- 定义this.properties或objectName.properties的javascript JSON对象
- Object.prototype using 'this'
- 在JavaScript类型的函数中避免self-this
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- Jquery Options using $(this)
- jQuery - 如何在 jquery 中访问 “this.options” dataSousrce 属性
- c.easing[this.options.specialEasing&this.options.sespeci
- 对象函数(){location.href=this.options.url);没有方法'apply'
- "类型错误:this.options为null"在OpenLayers.Protocol.HTTP中