-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_myPlugins.js
More file actions
37 lines (37 loc) · 1.14 KB
/
20_myPlugins.js
File metadata and controls
37 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if(window.$===undefined){
throw new Error("myPlugins库依赖于jQuery库")
}
jQuery.fn.dropdown=function(){
//this->$("...")
//找到this下的ul,侵入dropdown-menu和fade class
this.children("ul")
.addClass("dropdown-menu fade");
//为this绑定hover
//找到this下的ul,切换in class
this.hover(function(){
$(this).children("ul").toggleClass("in");
});
}
//$("#my-dropdown").dropdown();
jQuery.fn.tabs=function(){
//this->$("...")
this.addClass("tabs");//为父元素侵入tabs class
//为第一个li和第一个div侵入active class
this.find("ul>li:first").addClass("active");
this.find("div:first").addClass("active");
//为ul下每个a绑定单击事件
this.children("ul").on("click","a",function(e){
e.preventDefault();//阻止默认行为
//如果当前a的父级li不是active的
if(!$(this).parent().hasClass("active")){
$(this).parent()
.addClass("active")
.siblings(".active")
.removeClass("active");
$(this).parent().parent()
.siblings(".active")
.removeClass("active");
$($(this).attr("href")).addClass("active");
}
});
}