js簡体字繁体字変換

35311 ワード


"en">
    
        "UTF-8">
              
    
    
    「javascript:zhuutran('s')」=「zhuclick」id=「zhuclickus」       | "javascript:zhuutran('t')"class="zh click"id="zh click t"      
     
       10年の生死は両茫としている.考えない.忘れられない.千里の孤坟は、话すところがなくて寂しいです.たとえ出会いは見知らぬはずだとしても、ほこりだらけで、鬢は霜のようです.    夜が来て幽夢とともに故郷に帰る.小軒窓化粧を直す.顔を見合わせても言葉がなく,ただ涙だけが千行である.年がら年中腸がちぎれ、明月の夜、短松岡.
     
    「javascript:zhuutran('s')」=id=「ddd」  テスト
    
        <span style="color:#008000;">//</span><span style="color:#008000;"> --------------             --------------------
        </span><span style="color:#008000;">//</span><span style="color:#008000;">s = simplified      t = traditional      n = normal     </span>
        <span style="color:#0000ff;">var</span> zh_default = <span style="color:#800000;">'</span><span style="color:#800000;">n</span><span style="color:#800000;">'</span>; <span style="color:#008000;">//</span><span style="color:#008000;">    ,     </span>
        <span style="color:#0000ff;">var</span> zh_choose = getQueryString(<span style="color:#800000;">"</span><span style="color:#800000;">ltype</span><span style="color:#800000;">"</span>); <span style="color:#008000;">//</span><span style="color:#008000;">    </span>
        <span style="color:#0000ff;">var</span> zh_expires = <span style="color:#800080;">7</span>; <span style="color:#008000;">//</span><span style="color:#008000;">cookie    </span>
        <span style="color:#0000ff;">var</span> zh_class = <span style="color:#800000;">'</span><span style="color:#800000;">zh_click</span><span style="color:#800000;">'</span>; <span style="color:#008000;">//</span><span style="color:#008000;">   class ,id class + s/t/n   </span>
        <span style="color:#0000ff;">var</span> zh_style_active = <span style="color:#800000;">'</span><span style="color:#800000;">font-weight:bold; color:red;</span><span style="color:#800000;">'</span>; <span style="color:#008000;">//</span><span style="color:#008000;">         </span>
        <span style="color:#0000ff;">var</span> zh_style_inactive = <span style="color:#800000;">''</span>; <span style="color:#008000;">//</span><span style="color:#008000;">          </span>
        <span style="color:#0000ff;">var</span> zh_browserLang = <span style="color:#800000;">''</span>; <span style="color:#008000;">//</span><span style="color:#008000;">     </span>
        <span style="color:#0000ff;">var</span> zh_autoLang_t = <span style="color:#0000ff;">true</span>; <span style="color:#008000;">//</span><span style="color:#008000;">               </span>
        <span style="color:#0000ff;">var</span> zh_autoLang_s = <span style="color:#0000ff;">false</span>; <span style="color:#008000;">//</span><span style="color:#008000;">               </span>
        <span style="color:#0000ff;">var</span> zh_autoLang_alert = <span style="color:#0000ff;">false</span>; <span style="color:#008000;">//</span><span style="color:#008000;">             
        </span><span style="color:#008000;">//</span><span style="color:#008000;">          </span>
        <span style="color:#0000ff;">var</span> zh_autoLang_msg = <span style="color:#800000;">'</span><span style="color:#800000;">      ,            
1. UTF-8 , .
2. ,
3. ,
4. cookie </span><span style="color:#800000;">'</span><span style="color:#000000;">; </span><span style="color:#0000ff;">var</span> zh_autoLang_checked = <span style="color:#800080;">0</span>; <span style="color:#008000;">//</span><span style="color:#008000;"> , cookie 1, 2, </span><span style="color:#008000;">//</span><span style="color:#008000;"> ,ie ,ff </span> <span style="color:#0000ff;">var</span> zh_langReg_t = /^zh-tw|zh-hk$/<span style="color:#000000;">i; </span><span style="color:#0000ff;">var</span> zh_langReg_s = /^zh-cn$/<span style="color:#000000;">i; </span><span style="color:#008000;">//</span><span style="color:#008000;"> , </span> <span style="color:#0000ff;">var</span> zh_s = <span style="color:#800000;">'</span><span style="color:#800000;"> </span><span style="color:#800000;">'</span><span style="color:#000000;">; </span><span style="color:#0000ff;">var</span> zh_t = <span style="color:#800000;">'</span><span style="color:#800000;"> </span><span style="color:#800000;">'</span><span style="color:#000000;">; String.prototype.tran</span>=<span style="color:#000000;">function(){ </span><span style="color:#0000ff;">var</span><span style="color:#000000;"> s1,s2; </span><span style="color:#0000ff;">if</span>(zh_choose==<span style="color:#800000;">'</span><span style="color:#800000;">t</span><span style="color:#800000;">'</span><span style="color:#000000;">){ s1 </span>=<span style="color:#000000;"> zh_s; s2 </span>=<span style="color:#000000;"> zh_t; }</span><span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span>(zh_choose==<span style="color:#800000;">'</span><span style="color:#800000;">s</span><span style="color:#800000;">'</span><span style="color:#000000;">){ s1 </span>=<span style="color:#000000;"> zh_t; s2 </span>=<span style="color:#000000;"> zh_s; }</span><span style="color:#0000ff;">else</span><span style="color:#000000;">{ </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span><span style="color:#000000;">; } </span><span style="color:#0000ff;">var</span> a = <span style="color:#800000;">''</span><span style="color:#000000;">; </span><span style="color:#0000ff;">var</span> l = <span style="color:#0000ff;">this</span><span style="color:#000000;">.length; </span><span style="color:#0000ff;">for</span>(<span style="color:#0000ff;">var</span> i=<span style="color:#800080;">0</span>;i<<span style="color:#0000ff;">this</span>.length;i++<span style="color:#000000;">){ </span><span style="color:#0000ff;">var</span> c = <span style="color:#0000ff;">this</span><span style="color:#000000;">.charAt(i); </span><span style="color:#0000ff;">var</span> p =<span style="color:#000000;"> s1.indexOf(c); a </span>+= p < <span style="color:#800080;">0</span> ?<span style="color:#000000;"> c : s2.charAt(p); } </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> a; } </span><span style="color:#008000;">//</span><span style="color:#008000;"> url </span> <span style="color:#000000;"> function getQueryString(name) { </span><span style="color:#0000ff;">var</span> reg = <span style="color:#0000ff;">new</span> RegExp(<span style="color:#800000;">"</span><span style="color:#800000;">(^|&)</span><span style="color:#800000;">"</span> + name + <span style="color:#800000;">"</span><span style="color:#800000;">=([^&]*)(&|$)</span><span style="color:#800000;">"</span>, <span style="color:#800000;">"</span><span style="color:#800000;">i</span><span style="color:#800000;">"</span><span style="color:#000000;">); </span><span style="color:#0000ff;">var</span> r = window.location.search.substr(<span style="color:#800080;">1</span><span style="color:#000000;">).match(reg); </span><span style="color:#0000ff;">if</span> (r != <span style="color:#0000ff;">null</span>) <span style="color:#0000ff;">return</span> unescape(r[<span style="color:#800080;">2</span>]); <span style="color:#0000ff;">return</span> <span style="color:#800000;">'</span><span style="color:#800000;">s</span><span style="color:#800000;">'</span><span style="color:#000000;">; } function setCookie(name, value){ </span><span style="color:#0000ff;">var</span> argv =<span style="color:#000000;"> setCookie.arguments; </span><span style="color:#0000ff;">var</span> argc =<span style="color:#000000;"> setCookie.arguments.length; </span><span style="color:#0000ff;">var</span> expires = (argc > <span style="color:#800080;">2</span>) ? argv[<span style="color:#800080;">2</span>] : <span style="color:#0000ff;">null</span><span style="color:#000000;">; </span><span style="color:#0000ff;">if</span>(expires != <span style="color:#0000ff;">null</span><span style="color:#000000;">){ </span><span style="color:#0000ff;">var</span> LargeExpDate = <span style="color:#0000ff;">new</span><span style="color:#000000;"> Date (); LargeExpDate.setTime(LargeExpDate.getTime() </span>+ (expires*<span style="color:#800080;">1000</span>*<span style="color:#800080;">3600</span>*<span style="color:#800080;">24</span><span style="color:#000000;">)); } document.cookie </span>= name + <span style="color:#800000;">"</span><span style="color:#800000;">=</span><span style="color:#800000;">"</span> + escape (value)+((expires == <span style="color:#0000ff;">null</span>) ? <span style="color:#800000;">""</span> : (<span style="color:#800000;">"</span><span style="color:#800000;">; expires=</span><span style="color:#800000;">"</span> +<span style="color:#000000;">LargeExpDate.toGMTString())); } function getCookie(Name){ </span><span style="color:#0000ff;">var</span> search = Name + <span style="color:#800000;">"</span><span style="color:#800000;">=</span><span style="color:#800000;">"</span><span style="color:#000000;">; </span><span style="color:#0000ff;">if</span>(document.cookie.length > <span style="color:#800080;">0</span><span style="color:#000000;">){ offset </span>=<span style="color:#000000;"> document.cookie.indexOf(search); </span><span style="color:#0000ff;">if</span>(offset != -<span style="color:#800080;">1</span><span style="color:#000000;">){ offset </span>+=<span style="color:#000000;"> search.length; end </span>= document.cookie.indexOf(<span style="color:#800000;">"</span><span style="color:#800000;">;</span><span style="color:#800000;">"</span><span style="color:#000000;">, offset); </span><span style="color:#0000ff;">if</span>(end == -<span style="color:#800080;">1</span><span style="color:#000000;">){ end </span>=<span style="color:#000000;"> document.cookie.length; } </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> unescape(document.cookie.substring(offset, end)); }</span><span style="color:#0000ff;">else</span><span style="color:#000000;">{ </span><span style="color:#0000ff;">return</span> <span style="color:#800000;">''</span><span style="color:#000000;">; } } } function zh_tranBody(obj){ </span><span style="color:#0000ff;">var</span> o = (<span style="color:#0000ff;">typeof</span>(obj) == <span style="color:#800000;">"</span><span style="color:#800000;">object</span><span style="color:#800000;">"</span>) ?<span style="color:#000000;"> obj.childNodes : document.body.childNodes; </span><span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">var</span> i = <span style="color:#800080;">0</span>; i < o.length; i++<span style="color:#000000;">){ </span><span style="color:#0000ff;">var</span> c =<span style="color:#000000;"> o.item(i); </span><span style="color:#0000ff;">if</span>(<span style="color:#800000;">'</span><span style="color:#800000;">||BR|HR|TEXTAREA|SCRIPT|</span><span style="color:#800000;">'</span>.indexOf(<span style="color:#800000;">"</span><span style="color:#800000;">|</span><span style="color:#800000;">"</span>+c.tagName+<span style="color:#800000;">"</span><span style="color:#800000;">|</span><span style="color:#800000;">"</span>) > <span style="color:#800080;">0</span>) <span style="color:#0000ff;">continue</span><span style="color:#000000;">; </span><span style="color:#0000ff;">if</span>(c.className ==<span style="color:#000000;"> zh_class){ </span><span style="color:#0000ff;">if</span>(c.id == zh_class + <span style="color:#800000;">'</span><span style="color:#800000;">_</span><span style="color:#800000;">'</span> +<span style="color:#000000;"> zh_choose){ c.setAttribute(</span><span style="color:#800000;">'</span><span style="color:#800000;">style</span><span style="color:#800000;">'</span><span style="color:#000000;">, zh_style_active); c.style.cssText </span>=<span style="color:#000000;"> zh_style_active; }</span><span style="color:#0000ff;">else</span><span style="color:#000000;">{ c.setAttribute(</span><span style="color:#800000;">'</span><span style="color:#800000;">style</span><span style="color:#800000;">'</span><span style="color:#000000;">, zh_style_inactive); c.style.cssText </span>=<span style="color:#000000;"> zh_style_inactive; } </span><span style="color:#0000ff;">continue</span><span style="color:#000000;">; } </span><span style="color:#0000ff;">if</span>(c.title != <span style="color:#800000;">''</span> && c.title != <span style="color:#0000ff;">null</span><span style="color:#000000;">){ c.title </span>=<span style="color:#000000;"> c.title.tran(); } </span><span style="color:#0000ff;">if</span>(c.alt != <span style="color:#800000;">''</span> && c.alt != <span style="color:#0000ff;">null</span><span style="color:#000000;">){ c.alt </span>=<span style="color:#000000;"> c.alt.tran(); } </span><span style="color:#0000ff;">if</span>(c.tagName == <span style="color:#800000;">"</span><span style="color:#800000;">INPUT</span><span style="color:#800000;">"</span> && c.value != <span style="color:#800000;">''</span> && c.type != <span style="color:#800000;">'</span><span style="color:#800000;">text</span><span style="color:#800000;">'</span> && c.type != <span style="color:#800000;">'</span><span style="color:#800000;">hidden</span><span style="color:#800000;">'</span> && c.type != <span style="color:#800000;">'</span><span style="color:#800000;">password</span><span style="color:#800000;">'</span><span style="color:#000000;">){ c.value </span>=<span style="color:#000000;"> c.value.tran(); } </span><span style="color:#0000ff;">if</span>(c.nodeType == <span style="color:#800080;">3</span><span style="color:#000000;">){ c.data </span>=<span style="color:#000000;"> c.data.tran(); }</span><span style="color:#0000ff;">else</span><span style="color:#000000;">{ zh_tranBody(c); } } } function zh_tran(go){ </span><span style="color:#0000ff;">if</span>(go) zh_choose =<span style="color:#000000;"> go; setCookie(</span><span style="color:#800000;">'</span><span style="color:#800000;">zh_choose</span><span style="color:#800000;">'</span><span style="color:#000000;">, zh_choose, zh_expires); </span><span style="color:#0000ff;">if</span>(go == <span style="color:#800000;">'</span><span style="color:#800000;">n</span><span style="color:#800000;">'</span><span style="color:#000000;">){ window.location.reload(); }</span><span style="color:#0000ff;">else</span><span style="color:#000000;"> { zh_tranBody(); } } function zh_getLang(){ </span><span style="color:#0000ff;">if</span>(getCookie(<span style="color:#800000;">'</span><span style="color:#800000;">zh_choose</span><span style="color:#800000;">'</span><span style="color:#000000;">)){ zh_choose </span>= getCookie(<span style="color:#800000;">'</span><span style="color:#800000;">zh_choose</span><span style="color:#800000;">'</span><span style="color:#000000;">); </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span><span style="color:#000000;">; } </span><span style="color:#0000ff;">if</span>(!zh_autoLang_t && !<span style="color:#000000;">zh_autoLang_s){ </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">; } </span><span style="color:#0000ff;">if</span>(getCookie(<span style="color:#800000;">'</span><span style="color:#800000;">zh_autoLang_checked</span><span style="color:#800000;">'</span><span style="color:#000000;">)){ </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">; } </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(navigator.language){ zh_browserLang </span>=<span style="color:#000000;"> navigator.language; }</span><span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span><span style="color:#000000;">(navigator.browserLanguage){ zh_browserLang </span>=<span style="color:#000000;"> navigator.browserLanguage; } </span><span style="color:#0000ff;">if</span>(zh_autoLang_t &&<span style="color:#000000;"> zh_langReg_t.test(zh_browserLang)){ zh_choose </span>= <span style="color:#800000;">'</span><span style="color:#800000;">t</span><span style="color:#800000;">'</span><span style="color:#000000;">; }</span><span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span>(zh_autoLang_s &&<span style="color:#000000;"> zh_langReg_s.test(zh_browserLang)){ zh_choose </span>= <span style="color:#800000;">'</span><span style="color:#800000;">s</span><span style="color:#800000;">'</span><span style="color:#000000;">; } zh_autoLang_checked </span>= <span style="color:#800080;">1</span><span style="color:#000000;">; setCookie(</span><span style="color:#800000;">'</span><span style="color:#800000;">zh_choose</span><span style="color:#800000;">'</span><span style="color:#000000;">, zh_choose, zh_expires); </span><span style="color:#0000ff;">if</span>(zh_choose ==<span style="color:#000000;"> zh_default){ </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">; } </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span><span style="color:#000000;">; } function zh_init(){ zh_getLang(); c </span>= document.getElementById(zh_class + <span style="color:#800000;">'</span><span style="color:#800000;">_</span><span style="color:#800000;">'</span> +<span style="color:#000000;"> zh_choose); </span><span style="color:#0000ff;">if</span>(zh_choose !=<span style="color:#000000;"> zh_default){ </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(window.onload){ window.onload_before_zh_init </span>=<span style="color:#000000;"> window.onload; window.onload </span>=<span style="color:#000000;"> function(){ zh_tran(zh_choose); </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(zh_autoLang_alert){ alert(zh_autoLang_msg); }; window.onload_before_zh_init(); }; }</span><span style="color:#0000ff;">else</span><span style="color:#000000;">{ window.onload </span>=<span style="color:#000000;"> function(){ zh_tran(zh_choose); </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(zh_autoLang_alert){ alert(zh_autoLang_msg); }; }; } } } zh_init(); </span>
 
転載先:https://www.cnblogs.com/jianghaidong/p/10032222.html