码迷,mamicode.com
首页 > Web开发 > 详细

encodeURIComponent()编码和decodeURIComponent()解码

时间:2015-04-25 16:30:41      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

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>

 

encodeURIComponent()编码和decodeURIComponent()解码

标签:

原文地址:http://www.cnblogs.com/xupeiyu/p/4455958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!