要在JavaScript中解码URL,请使用decodeURI()
方法。
您可以尝试运行以下代码来解码URL-
<!DOCTYPE html> <html> <body> <button onclick="display()">Check</button> <p id="demo"></p> <script> function display() { var uri = "welcome msg.jsp?name=åmit&sub=programming"; //首先编码 var encode = encodeURI(uri); var decode = decodeURI(encode); var result = "Encode= " + encode + "<br>" + "Decode= " + decode; document.getElementById("demo").innerHTML = result; } </script> </body> </html>