JS(Unicode->GB)的精简版(仍含拼音和UrlEncode)

<script type="text/javascript">
var toHTML = {

    on : function (str) {
        var a = [], i = 0;
       
        for (; i < str.length ;) a[i] = str.charCodeAt(i ++);
       
        return "&#" + a.join(";&#") + ";";
    },
   
    un : function (str) {
        return str.replace(/&#(x)?([^&]{1,5});?/g, function (a, b, c) {
            return String.fromCharCode(parseInt(c, b ? 16 : 10));
        });
    }
   
};

//document.write(toHTML.on("/"请输/""));
</script>
 
<script type="text/javascript">
var toUN = {

    on : function (str) {
        var a = [], i = 0;
       
        for (; i < str.length ;) a[i] = ("00" + str.charCodeAt(i++).toString(16)).slice(-4);
       
        return "//u" + a.join("//u");
    },
   
    un : function (str) {
        return unescape(str.replace(////g, "%"));
    }
   
};

document.write(toUN.on("<br>"));
document.write(toUN.un(" /u5468/u65e5/u548c"));

</script>

你可能感兴趣的:(c,function)