机器人
『回复列表(767|隐藏机器人聊天)』
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL解码工具</title>
<style>
#output {
margin-top: 10px;
font-family: monospace;
}
</style>
</head>
<body>
<h1>URL解码工具</h1>
<form id="url-form">
<label for="encoded-url">请输入编码后的URL:</label>
<input type="text" id="encoded-url" value="https://t.com/f/search/res?isnew=1&kw=&qw=%D2%C6%B6%AF%D4%C6%C5%CC&rn=10&un=&only_thread=0&sm=1&sd=&ed=&pn=1" readonly>
<button type="button" onclick="decodeUrl()">解码</button>
</form>
<div id="output"></div>
<script>
function decodeUrl() {
const encodedUrl = document.getElementById('encoded-url').value;
const decodedUrl = decodeURIComponent(encodedUrl);
document.getElementById('output').innerText = decodedUrl;
}
</script>
</body>
</html>
这个HTML页面包含一个预填了示例URL的文本输入框,虽然它被设置为只读(readonly
),但用户仍然可以通过复制粘贴来替换内容。点击“解码”按钮后,会调用decodeUrl
函数对URL进行解码,并将结果展示在输出区域中。
@咯叽,抱歉给您带来了困扰,代码应该是有效的。不过,请确保JavaScript在DOM加载完成后执行,有时由于脚本执行时机问题可能会导致事件绑定失效。以下是修改后的HTML,将JavaScript部分放入window.onload
中以确保DOM加载完成后再执行:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL解码工具</title>
<style>
#output {
margin-top: 10px;
font-family: monospace;
}
</style>
</head>
<body>
<h1>URL解码工具</h1>
<form id="url-form">
<label for="encoded-url">请输入编码后的URL:</label>
<input type="text" id="encoded-url" value="https://t.com/f/search/res?isnew=1&kw=&qw=%D2%C6%B6%AF%D4%C6%C5%CC&rn=10&un=&only_thread=0&sm=1&sd=&ed=&pn=1" readonly>
<button type="button" onclick="decodeUrl()">解码</button>
</form>
<div id="output"></div>
<script>
window.onload = function() {
document.getElementById('decode-btn').onclick = decodeUrl;
function decodeUrl() {
const encodedUrl = document.getElementById('encoded-url').value;
const decodedUrl = decodeURIComponent(encodedUrl);
document.getElementById('output').innerText = decodedUrl;
}
};
</script>
</body>
</html>
尽管在这个例子中直接在HTML上使用onclick
属性应该有效,但为了保证万无一失,这里采用了window.onload
的方式来确保DOM加载完成后执行JavaScript逻辑。同时,确保你的浏览器支持decodeURIComponent
方法,并且该方法应用于正确的编码格式的URL字符串。