jQuery中$this和$(this)的区别介绍(一看就懂)
//this其实是一个Html元素。
//$this只是个变量名,加$是为说明其是个jquery对象。
//而$(this)是个转换,将this表示的dom对象转为jquery对象,这样就可以使用jquery提供的方法操作。
(function($){
$.fn.hilight=function(options){
debug(this);
vardefaults={
foreground:'red',
background:'yellow'
};
varopts=$.extend({},$.fn.hilight.defaults,options);
returnthis.each(function(){
//this其实是一个Html元素。
//$this只是个变量名,加$是为说明其是个jquery对象。
//而$(this)是个转换,将this表示的dom对象转为jquery对象,这样就可以使用jquery提供的方法操作。
$this=$(this);
//buildelementspecificoptions
varo=$.meta?$.extend({},opts,$this.data()):opts;
//updateelementstyles
$this.css({
backgroundColor:o.background,
color:o.foreground
});
varmarkup=$this.html();
//callourformatfunction
markup=$.fn.hilight.format(markup);
$this.html(markup);
});
};
//defineourformatfunction
$.fn.hilight.format=function(txt){
return'<strong>'+txt+'</strong>';
};
//插件的defaults
$.fn.hilight.defaults={
foreground:'red',
background:'yellow'
};
functiondebug($obj){
if(window.console&&window.console.log){
window.console.log('hilightselectioncount:'+$obj.size());
}
};
})(jQuery)
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下