Tag的自訂類

來源:互聯網
上載者:User

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>無標題頁</title> <link href="http://www.17mm.net/StyleSheet.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript" src="http://www.17mm.net/TagPage.js"></script> <script language="javascript" type="text/javascript"> function crea(){ var obj = new CTagPages("maintag"); obj.add(new CTPage("files","檔案1","content6"));//建立一個文檔中不存在的內容頁 obj.add(new CTPage("edits","編輯","content2")); obj.add(new CTPage("windows","視窗","content3")); obj.add(new CTPage("helps","協助","content4")); document.all.tag.innerHTML = obj; obj.setTag(1); } window.onload = crea; </script></head><body> <hr /> <div id="tag"></div> <!-- <div id="content1" class="content" style="background-color:Green;">我愛你中國</div>--> <div id="content2" class="content" style="background-color:Aqua;">愛你中國</div> <div id="content3" class="content" style="background-color:Fuchsia">中國愛你</div> <div id="content4" class="content" style="background-color:Blue">很愛你中國</div> <div id="tag1"></div></body></html>

[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]

CTagPages
屬性
Tagpages  標籤數組

方法

[n]   檢索標籤
Add   增加標籤頁
Delete  刪除標籤頁
Update  更新標籤頁
Insert  插入標籤頁
Clear  清空標籤頁
SetTag  設定一個標籤被選中,參數可以是TAG的ID也可以是序號
GetTag  得到被選中的TAG對象

CTPage
屬性
tagId     標籤ID    
tagCaption 標籤上顯示的文字
tagContId  標籤內容ID

JS類下載

// 使用方法
//      1.var tagpages = new CTagPages("maintag");建立一個TagPages對象,參數為這個標籤頁集合的ID,區分其它標籤頁
//      2.var tagpage = new CTPage("files","檔案","content6");建立一個標籤頁,參數1指這個標籤頁的ID,參數2標籤文字,
//                      參數3與此標籤相對的DIV,如果指定一個文檔中不存在的DIV則系統會自動建立一個DIV;
//      3.tagpages.add(tagpage);使用ADD方法增加把標籤增加到標籤頁中.
//      4.document.all.tag.innerHTML = tagpages;把標籤頁增加到文檔中.
//      5.tagpages.setTag(1)或tagpages.setTag("files");設定預設選中的標籤頁,參數可以使用[數字]和[ID名稱]兩種方式
//     

//公開變數
var currentTag = null;
var currentDiv = null;

//////////////////////////////////////////////////////////////////
////////////////////////////////
//單個標籤對象
function CTPage(tagId, tagCaption, tagDiv){
    this.checkDiv(tagDiv);
    this.id = tagId;
    this.caption = tagCaption;
    this.divid = tagDiv;
    this.selected = false;
}

function tagToString(){
    var str = "<li class=\"";
        str += this.selected?"focus":"blur";
        str += "\" id=\"" + this.id +"\"" +
              " divid=\"" + this.divid +"\"" +
              " onclick=\"secBoard(this)\"" +
              " >"+ this.caption + "</li>";
    return str;
}

function CheckDiv(divname){
    var tdiv = document.getElementById(divname);
    if(!tdiv){
        tdiv = document.createElement("DIV");
        tdiv.id = divname;
        tdiv.className = "content";
        tdiv.innerHTML = "新的";
        document.body.appendChild(tdiv);
    }
    tdiv.style.display = "none";
}
CTPage.prototype.checkDiv = CheckDiv;
CTPage.prototype.toString = tagToString;
////////////////////////////////////////////////////////////////
//////////////////////////////
//標籤集合對象

function CTagPages(id){
    this.id = id;
    this.tagpages = new Array();
}

function Add(objtg){
    this.tagpages[this.tagpages.length] = objtg;
}

function pageToString(){
    var str="<ul id=\""+this.id+"\" class=\"tagpage\">";
    for(var i=0; i<this.tagpages.length; i++){
        str += this.tagpages[i];
    }
    str +="</ul>";
   
    return str;
}

function Index(n){
    if(n>this.tagpages.length-1 || n<0){
        return;
    }else{
        return this.tagpages[n];
    }
}

function SetTag(n){
    var curtag = null;
    if(typeof(n)=="string"){
        curtag = document.getElementById(n);
    }else{
        var curtag = document.getElementById(this.id).childNodes[n];
    }
    if(curtag){
        if(currentTag && currentDiv){
            currentTag.className = "blur";
            currentDiv.style.display = "none";
        }
        curtag.className = "focus";
        currentTag = curtag;
        var curDiv = document.getElementById(curtag.divid);
        curDiv.style.display = "block";
        currentDiv = curDiv;
    }
}

CTagPages.prototype.setTag = SetTag;
CTagPages.prototype.index = Index;
CTagPages.prototype.add = Add;
CTagPages.prototype.toString = pageToString;

////////////////////////////////////////////////////////////////
/////////////////////////////////
//通用函數

function secBoard(obj)
{
    //var obj = event.srcElement;
    currentTag.className = "blur";
    currentTag = obj;
    currentTag.className = "focus";
   
    currentDiv.style.display = "none";
    currentDiv = document.getElementById(obj.divid);
    currentDiv.style.display = "block";
}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.