js解析javaUrl编码

在JAVA中设置了编码格式如下 
java.net.URLEncoder.encode(loginName,"gbk"); 

但如何在JS中进行urlDecode呢?具体代码如下: 
<script type="text/vbscript"> 
<!-- 
function str2asc(strstr) 
    str2asc   =   hex(asc(strstr)) 
end function 

function   asc2str(ascasc) 
    asc2str   =   chr(ascasc) 
end function 
'--> 
</script> 


<script type="text/javascript"> 
<!-- 
function urlEncode(str) 
{ 
    var ret = ""; 
    var strSpecial = "!\"#$%&’()*+,/:;<=>?[]^`{|}~%"; 
    var tt = ""; 
    for(var i = 0; i < str.length; i++) 
    { 
        var chr = str.charAt(i); 
        var c = str2asc(chr); 
        tt += chr + ":" + c + "n"; 
        if (parseInt("0x" + c) > 0x7f) 
        { 
            ret += "%" + c.slice(0,2) + "%" + c.slice(-2); 
        } 
        else 
        { 
            if (chr == " ") 
                ret += "+"; 
            else if (strSpecial.indexOf(chr) != -1) 
                ret += "%" + c.toString(16); 
            else 
                ret += chr; 
        } 
    } 
   
    return ret; 
} 

function urlDecode(str) 
{ 
    var ret = ""; 
    for (var i = 0; i < str.length; i++) 
    { 
        var chr = str.charAt(i); 
        if (chr == "+") 
        { 
            ret += " "; 
        } 
        else if (chr == "%") 
        { 
            var asc = str.substring(i+1, i+3); 
            if (parseInt("0x"+asc) > 0x7f) 
            { 
                ret += asc2str(parseInt("0x" + asc+str.substring(i+4, i+6))); 
                i += 5; 
            } 
            else 
            { 
                ret += asc2str(parseInt("0x"+asc)); 
                i += 2; 
            } 
        } 
        else 
        { 
            ret += chr; 
        } 
    } 
   
    return ret; 
} 
--> 
</script> 

你可能感兴趣的:(java)