tabview 탭 전환 대상 작성
4435 단어 view
var dotA = {
trim:function(string){
return string.replace(/^\s+|\s+$/g,'');
},
/* id className or Dom Elements */
one:function(selector){
selector = this.trim(selector);
if(typeof selector == 'string')
if(selector.indexOf('#') > -1){
var aSel = selector.split("#");
return document.getElementById(aSel[1]);
}
else if(selector.indexOf('.') > -1){
var aSel = selector.split(".");
var tagName = aSel[0];
var className = aSel[1];
var elements = document.getElementsByTagName(tagName || "*");
if(elements)
for(var i = 0 , len = elements.length ; i < len ;i++){
if(elements[i].className.indexOf(className) > -1){
return elements[i];
break;
}
}
else
return null;
}else{
return document.getElementsByTagName(selector)[0];
}
else
return selector;
},
/* add event to elements method */
addEvent:function(el, type, fn, capture) {
if (el && el.addEventListener) {
el.addEventListener(type, fn, capture);
} else if (el && el.attachEvent) {
el.attachEvent("on" + type, fn);
}
},
/*
add a class to a elements
el:id or htmlElement
*/
addClass:function(el,className){
el = (typeof el == 'string') ? this.one('#' + el) : el;
if(!(el.className.indexOf(className) > -1)){
el.className += " "+className;
el.className = dotA.trim(el.className);
}
},
removeClass:function(el,className){
el = (typeof el == 'string') ? this.one('#' + el) : el;
el.className = dotA.trim(el.className.replace(className,''));
},
hasClass:function(el,className){
el = (typeof el == 'string') ? this.one('#' + el) : el;
if((el.className.indexOf(className) > -1)){
return true
}else
return false
},
stopEvent:function(e){
if(e.target){
e.preventDefault()
}else{
e.returnValue = false;
}
}
};
dotA.tabView = {
tab_list_selected:null,
tab_panel_selected:null,
selected_index:0,
toggleTab:function(e){
e = e.srcElement || e.target;
if(e.parentNode.tagName == 'LI'){
var liTag = e.parentNode;
if(!dotA.hasClass(liTag,'dota-tablist-selected')){
dotA.removeClass(tab_list_selected,'dota-tablist-selected');
dotA.addClass(liTag,'dota-tablist-selected');
tab_list_selected = liTag;
dotA.removeClass(tab_panel_selected,'dota-tab-selected');
dotA.addClass(dotA.one(e.getAttribute('href')),'dota-tab-selected');
tab_panel_selected = dotA.one(e.getAttribute('href'));
}
}
return false;
},
/* el is a selector or a htmlElement*/
render:function(el){
el = (typeof el == 'string') ? dotA.one(el) : el;
/* add class for elements */
dotA.addClass(el,'dota-tabview');
var ul = el.getElementsByTagName('ul')[0];
dotA.addClass(ul,'dota-tabview-list');
var div = el.getElementsByTagName('div')[0];
dotA.addClass(div,'dota-tabview-panel');
var tabpanels = div.children;
for(var i = 0 ; i < tabpanels.length ; i++){
dotA.addClass(tabpanels[i],'dota-tab-panel');
};
var ulist = ul.children;
dotA.addClass(ulist[this.selected_index],'dota-tablist-selected');
tab_list_selected = ulist[this.selected_index];
dotA.addClass(tabpanels[this.selected_index],'dota-tab-selected');
tab_panel_selected = tabpanels[this.selected_index];
dotA.addEvent(ul,'click',dotA.tabView.toggleTab);
},
setCurrent:function(index){
this.selected_index = index;
}
};
dotA.tabView.setCurrent(1);
dotA.tabView.render('#tabview');
첨부 파일 안에 바로 예시가 있다
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Getting Started with Zend Framework 2 - ViewBy default, the action and view in the controller are one-to-one correspondence, such as HellowordController::indexActio...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.