JS网页转换繁体(简化版)


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS网页转换繁体(简化版)</title>


<button id='btn'>转换繁體</button><hr>
<input value="师不必贤于弟子" type="button" /><hr>
<input type="text" value="师不必贤于弟子" /><hr>
<select>
<option>师不必贤于弟子</option>
</select><hr>
<a href="#">师不必贤于弟子</a><hr>
师不必贤于弟子<hr>
<textarea>师不必贤于弟子</textarea><hr>



<script>
var btnx=document.getElementById("btn");
btnx.onclick= new Function("myFunc();return false");
btnx.innerHTML=toFanti(btnx.innerHTML);


function myFunc(fobj){
    if(typeof(fobj)=="object"){
        var obj=fobj.childNodes;
    }
    else {
        var s=btnx.innerHTML.toString();
        btnx.innerHTML=toFanti(s);
        var obj=document.body.childNodes;
    }
    console.log(obj);
    for(var i=0;i<obj.length;i++){
        var v=obj.item(i);
        if("|BR|HR|SCRIPT|".indexOf("|"+v.tagName+"|")>0||v==btnx) {
            continue;
        }
        if(v.tagName=="INPUT"&&v.value!=""&&v.type!="hidden"){
            v.value=toFanti(v.value);
        }
        if(v.nodeType==3){
            v.data=toFanti(v.data);
        }
        else {
            myFunc(v);
        }
    }
}


function toFanti(cc){
    var str='',ss='贤师',tt='賢師';
    for(var i=0;i<cc.length;i++){
        var ch=cc.charAt(i);
        var index=ss.indexOf(ch);
        if(cc.charCodeAt(i)>10000&&index!=-1){
            str+=tt.charAt(index);
        }
        else {
            str+=ch;
        }
    }
    return str;
}


</script>




程序运行结果如下,点击这里亲自运行看看