html1:
<!DOCTYPE HTML>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>test</title>
<a href="2.htm" v="任晓强" id="test">go</a>
<style>
.cur{color:#f00;}
</style>
<script>
test.href = test.href + "?" + encodeURIComponent(test.getAttribute("v"));//对任晓强进行编码
</script>
html2:
<!DOCTYPE HTML>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>test</title>
<div id="test"></div>
<style>
.cur{color:#f00;}
</style>
<script>
var name = decodeURIComponent(location.search).replace("?",""); //解码并替换网址
//decodeURIComponent(name);
console.log(name)
test.innerHTML = "你好" + name; //给test赋值
</script>
本文介绍了一个简单的HTML页面如何使用JavaScript进行URL参数的编码与解码操作。通过两个页面之间的互动,演示了如何将特定字符串编码为URL参数的一部分,并在目标页面中解码这些参数来显示原始信息。
707

被折叠的 条评论
为什么被折叠?



