jQuery.fn.tabs = function(control){
var element = $(this);
control = $(control);
element.find("li").bind("click", function(){element.find("li").removeClass("active");
$(this).addClass("active");var tabName = $(this).attr("data-tab");
control.find(">[data-tab]").removeClass("active");
control.find(">[data-tab='" + tabName + "']").addClass("active");
});element.find("li:first").addClass("active");return this;
};var element = $(this);这句是什么意思啊,为什么还要把它转换成jquery对象啊,this不就是实例出来的一个jQuery的实例吗,还加什么$啊?
var element = $(this);
control = $(control);
element.find("li").bind("click", function(){element.find("li").removeClass("active");
$(this).addClass("active");var tabName = $(this).attr("data-tab");
control.find(">[data-tab]").removeClass("active");
control.find(">[data-tab='" + tabName + "']").addClass("active");
});element.find("li:first").addClass("active");return this;
};var element = $(this);这句是什么意思啊,为什么还要把它转换成jquery对象啊,this不就是实例出来的一个jQuery的实例吗,还加什么$啊?
解决方案 »
- 一组输入框如何便捷的判断非空?
- 快疯掉了,有没有碰到这种怪事?
- 菜鸟求教
- 为什么啊我加'(' ')'后eval 才能让让json字符串转换成对象
- 使用getElementById(idx)时出错,提示参数无效!写了好多js,这还是第一次遇到,大家帮我看看问题处在哪呢?
- jsp中怎么将jsp定义的参数传给javascript定义的函数?
- 高分求列表拖动代码
- 如何屏蔽anchor的转页操作
- 怎样替换用户输入字符串中的非法字符?在线等。。。。马上给分!
- 如何重复为cookie添加数据 或者替换cookie数据
- 大神帮忙 下拉菜单取不到值 SSH EL表达式
- 能否通过js让页面使用本地文件?(不使用插件或者扩展)
$(this) 表示的是用jquery封装候的当前对象this 对象可以直接访问其属性,比如 this.style.display="none"
$(this) 只能使用jquery提供的方法访问,比如 $(this).css("display","none")
control = $(control);
element.find("li").bind("click", function(){
element.find("li").removeClass("active"); //这里要用到外层的对象
$(this).addClass("active"); //这个 $(this) 是套红的那个
$(this)是jquery对象,this dom对象,另外$(this)[0]返回的也是dom对象
<input id="aa" type="text" value="123" />
<script>
$.fn.tabs = function () {
console.log(this);
console.log($(this));
}
$('#aa').tabs();
</script>
书也不一定就100%正确了,而且代码演示这种错误更加多,当然在$一次也没什么