<!DOCTYPE html>
<html>
<head>
<title>链接Base64编码与解码示例</title>
</head>
<body>
<input type="text" id="urlInput" placeholder="输入链接">
<button onclick="encodeURL()">编码链接</button>
<p>编码结果:</p>
<textarea id="encodedOutput" rows="5" readonly></textarea>
<button onclick="decodeURL()">解码链接</button>
<p>解码结果:</p>
<textarea id="decodedOutput" rows="5" readonly></textarea>
<script>
function encodeURL() {
var urlInput = document.getElementById("urlInput").value;
var encodedOutput = document.getElementById("encodedOutput");
var encodedURL = btoa(encodeURIComponent(urlInput));
encodedOutput.value = encodedURL;
}
function decodeURL() {
var encodedURL = document.getElementById("encodedOutput").value;
var decodedOutput = document.getElementById("decodedOutput");
var decodedURL = decodeURIComponent(atob(encodedURL));
decodedOutput.value = decodedURL;
}
</script>
</body>
</html>