simpleTabs_wev8.js
2.1 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function ($) {
$.fn.simpleTabs = function (){
var p = window.location.pathname;
$tabTitles = this.children("ul").children("li");
function contorlDisplay(){
$tabTitles.each(function(i){
var $this = $(this);
var h = $this.attr("href");
if(!$this.hasClass("selected")){
$(h).hide();
}else{
//记录到cookie当前点的是第几个tab
if(typeof(FormmodeUtil) != "undefined"){
FormmodeUtil.writeCookie(p, i);
}
$(h).show();
var $iframe = $(h).children("iframe");
var lazySrc = $iframe.attr("lazy-src");
if(lazySrc && lazySrc != ""){
if(typeof(beforeIframeLoad) == "function"){
beforeIframeLoad($iframe[0]);
}
var onLoadedCallFn = function(){
if(typeof(whenIframeOnLoad) == "function"){
whenIframeOnLoad($iframe[0]);
}
};
if(document.attachEvent){
$iframe[0].attachEvent("onload", onLoadedCallFn);
}else if(document.addEventListener){
$iframe[0].addEventListener("load", onLoadedCallFn, false);
}
$iframe[0].src = lazySrc;
$iframe.removeAttr("lazy-src");
}else{
if(typeof(chooseLoadedIframe) == "function"){
chooseLoadedIframe($iframe[0]);
}
}
}
});
}
//获取cookie中上次点的是第几个tab
var lastIndex = null;
if(typeof(FormmodeUtil) != "undefined"){
lastIndex = FormmodeUtil.readCookie(p);
}
if(lastIndex && lastIndex < $tabTitles.length){ //从cookie中设置选择
$tabTitles.eq(lastIndex).addClass("selected");
}else{ //从页面代码默认选中属性设置选中
$tabTitles.filter("[defaultSelected='true']").eq(0).addClass("selected"); //加个eq(0)是防止有多个defaultSelected为true的元素
}
contorlDisplay();
$tabTitles.click(function(){
$tabTitles.removeClass("selected");
$(this).addClass("selected");
contorlDisplay();
});
};
})(jQuery);