请教:
colorbox是一个插件,然后写他的属性:
$.colorbox = {
obj:{
turn: function(color){...}
};
}怎样在turn方法里拿到调用colorbox元素,比如说有$(div).colorbox(),怎样拿到$(div)?
colorbox是一个插件,然后写他的属性:
$.colorbox = {
obj:{
turn: function(color){...}
};
}怎样在turn方法里拿到调用colorbox元素,比如说有$(div).colorbox(),怎样拿到$(div)?
或者是
$("div").children("colorbox");你试一下哪个是可以的
插件是这样声明:
$.fn.colorbox = function(option){
...
};
如果有div调用这个插件,在colorbox的function里可以用jQuery(this)拿到$(div),
后面的属性是这样定义的:
jQuery.colorbox = {
a: {},
obj:{
//这里先把调用元素$(div)放obj属性好了。
self: function(){
//在这里获取调用colorbox()的div Object。
//试过用return jQuery(this)好像不行。jQuery.colorbox.a.parent不知道对不对。
},
turn: function(){
var self = jQuery.colorbox.obj.self();
}
}
};
----------------
根据this的定义,this是指调用函数时,该函数所挂靠的object,全局函数挂靠在window对象下。所以,this,就是指$(div)