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.com/');
document.write(encodeURIComponent(result2));
</script>
</body>
</html>输出
http%3A%2F%2Fwww.qries.com%2F http%253A%252F%252Fwww.tutorialspoint.com%252F
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP