javascript:Globalグローバルオブジェクト、符号化復号、eval方法
2310 ワード
type</span>=text/javascript charset=utf-<span class="hljs-number">8</span>>
<span class="hljs-comment">//Global , </span>
<span class="hljs-javadoc">/**
*
* :encodeURI,encodeURIComponent, ,
* :decodeURI,decodeURIComponent
* , :
* encodeURIComponent decodeURI ,
* encodeURI decodeURIComponent
* escape,unescape
*/</span>
<span class="hljs-keyword">var</span> url = <span class="hljs-string">'http://www.baidu.com cn'</span>;
<span class="hljs-comment">// </span>
<span class="hljs-keyword">var</span> str1 = encodeURI(url); <span class="hljs-comment">// :http://www.baidu.com%20cn </span>
<span class="hljs-keyword">var</span> str2 = encodeURIComponent(url); <span class="hljs-comment">// :http%3A%2F%2Fwww.baidu.com%20cn </span>
document.write(str2);
<span class="hljs-comment">// </span>
<span class="hljs-keyword">var</span> str3 = decodeURI(str1);
<span class="hljs-keyword">var</span> str4 = decodeURIComponent(str2);
<span class="hljs-javadoc">/**
* eval(string) , javascript
*/</span>
<span class="hljs-comment">// js </span>
<span class="hljs-keyword">var</span> str5 = <span class="hljs-string">"var a=30,b=20"</span>;
eval(str5);
alert(a+b);
<span class="hljs-comment">// </span>
<span class="hljs-keyword">var</span> strObj = <span class="hljs-string">"{name:'Lingbo' , age:20}"</span>;
<span class="hljs-keyword">var</span> obj = eval(<span class="hljs-string">'('</span>+ strObj +<span class="hljs-string">')'</span>);
alert(obj.name);