javascript 繁體中文轉碼

來源:互聯網
上載者: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>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>網頁特效 繁體中文轉碼</title>

</head>

<body>

<a href="#" name="stranlink">繁體中文</a>
中華人民共和國
<script language="網頁特效"  type="text/javascript">
var default_isft = 0; //預設是否繁體,0-簡體,1-繁體  
var stranit_delay = 50 //翻譯延時毫秒(設這個的目的是讓網頁先流暢的顯現出來)  
//-------代碼開始,以下別改-------  
//轉換文本  
function strantext(txt,toft,chgtxt)  
{  
if(txt==""||txt==null)return ""
toft=toft==null?bodyisft:toft  
if(chgtxt)txt=txt.replace((toft?"簡":"繁"),(toft?"繁":"簡"))  
if(toft){return traditionalized(txt)}  
else {return simplized(txt)}  
}  
//轉換對象,使用遞迴,逐層剝到文本  
function stranbody(fobj)  
{  
if(typeof(fobj)=="object"){var obj=fobj.childnodes}  
else
{  
var tmptxt=stranlink_obj.innerhtml.tostring()  
if(tmptxt.indexof("簡")<0)  
{  
bodyisft=1  
stranlink_obj.innerhtml=strantext(tmptxt,0,1)  
stranlink.title=strantext(stranlink.title,0,1)  
}  
else
{  
bodyisft=0  
stranlink_obj.innerhtml=strantext(tmptxt,1,1)  
stranlink.title=strantext(stranlink.title,1,1)  
}  
setcookie(jf_cn,bodyisft,7)  
var obj=document.body.childnodes  
}  
for(var i=0;i<obj.length;i++)  
{  
var oo=obj.item(i)  
if("||br|hr|textarea|".indexof("|"+oo.tagname+"|")>0||oo==stranlink_obj)continue;  
if(oo.title!=""&&oo.title!=null)oo.title=strantext(oo.title);  
if(oo.alt!=""&&oo.alt!=null)oo.alt=strantext(oo.alt);  
if(oo.tagname=="input"&&oo.value!=""&&oo.type!="text"&&oo.type!="hidden")oo.value=strantext(oo.value);  
if(oo.nodetype==3){oo.data=strantext(oo.data)}  
else stranbody(oo)  
}  
}  
function jtpystr()  
{  
return '';  
}  
function ftpystr()  
{  
return '';  
}  
function traditionalized(cc){  
var str='',ss=jtpystr(),tt=ftpystr();  
for(var i=0;i<cc.length;i++)  
{  
if(cc.charcodeat(i)>10000&&ss.indexof(cc.charat(i))!=-1)str+=tt.charat(ss.indexof(cc.charat(i)));  
else str+=cc.charat(i);  
}  
return str;  
}  
function simplized(cc){  
var str='',ss=jtpystr(),tt=ftpystr();  
for(var i=0;i<cc.length;i++)  
{  
if(cc.charcodeat(i)>10000&&tt.indexof(cc.charat(i))!=-1)str+=ss.charat(tt.indexof(cc.charat(i)));  
else str+=cc.charat(i);  
}  
return str;  
}  
function setcookie(name, value) //cookies設定  
{  
var argv = setcookie.arguments;  
var argc = setcookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
if(expires!=null)  
{  
var largeexpdate = new date ();  
largeexpdate.settime(largeexpdate.gettime() + (expires*1000*3600*24));  
}  
document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +largeexpdate.togmtstring()));  
}  
function getcookie(name)   //cookies讀取  
{  
var search = name + "="
if(document.cookie.length > 0)  
{  
offset = document.cookie.indexof(search)  
if(offset != -1)  
{  
offset += search.length  
end = document.cookie.indexof(";", offset)  
if(end == -1) end = document.cookie.length  
return unescape(document.cookie.substring(offset, end))  
}  
else return ""
}  
}  
var stranlink_obj=document.getelementbyid("stranlink")  
if (stranlink_obj)  
{  
var jf_cn="ft"+self.location.hostname.tostring().replace(/./g,"")  
var bodyisft=getcookie(jf_cn)  
if(bodyisft!="1")bodyisft=default_isft  
with(stranlink_obj)  
{  
if(typeof(document.all)!="object") //非ie瀏覽器  
{  
href=""
}  
else
{  
href="#";  
onclick= new function("stranbody();return false")  
}  
title=strantext("繁體中文",1,1)  
innerhtml=strantext(innerhtml,1,1)  
}  
if(bodyisft=="1"){settimeout("stranbody()",stranit_delay)}  

</script>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.