JavaScript 中的 encodeURIComponent() 函式


encodeURIComponent() 函式接受包含 URI 的字串值,然後使用數字(1 到 4)和轉義序列替換其中的字元以對其進行編碼。

語法

以下是其語法:

encodeURIComponent('http://www.qries.com/');

示例

 即時演示

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result1 = encodeURIComponent('http://www.qries.com/');
      document.write(result1);
      document.write("<br>");
      var result2 = encodeURIComponent('https://tutorialspoint.tw/');
      document.write(encodeURIComponent(result2));
   </script>
</body>
</html>

輸出

http%3A%2F%2Fwww.qries.com%2F
http%253A%252F%252Fwww.tutorialspoint.com%252F

更新於: 25-06-2020

65 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始學習
廣告