您的位置:首页 > 其它

encodeURIComponent()编码和decodeURIComponent()解码

2015-04-25 15:06 375 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐