<script>
var s1 = "sdf (dsg)"
alert(escape(s1));
</script>

解决方案 »

  1.   

    我在中寫入的值為"TERRAILLON (SPAIN SHIPMENT)"在中讀出的值為 :
    TERRAILLON+%28SPAIN+SHIPMENT%29
    怎麼把它變成:"TERRAILLON (SPAIN SHIPMENT)"
    strcom_name.search("+")會出錯。
      

  2.   

    先encode写入cookie,读出时decode
      

  3.   

    IE5.5以下自己别程序替换,IE5.5+用
    <script>
    alert(decodeURI("TERRAILLON+%28SPAIN+SHIPMENT%29").replace(/\+/g," "));alert(decodeURIComponent("TERRAILLON+%28SPAIN+SHIPMENT%29").replace(/\+/g," "));
    </script>
      

  4.   

    我是用escape和unescape解决的:<SCRIPT LANGUAGE="JavaScript">
    <!--
    function getCookieByName(name){
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
    return unescape(arr[2]);
    else
    return null
    }  //改装了以前从秋水那里弄来的读cookie的函数function setCookie(name,value){
    document.cookie= name+"="+escape(value)
    }setCookie("test","TERRAILLON (SPAIN SHIPMENT)");
    alert(getCookieByName("test"))//-->
    </SCRIPT>
      

  5.   

    thanks to all!三星級大俠  qiushuiwuhen(秋水无恨):
    您好!<script>
    alert(decodeURI("TERRAILLON+%28SPAIN+SHIPMENT%29").replace(/\+/g," "));alert(decodeURIComponent("TERRAILLON+%28SPAIN+SHIPMENT%29").replace(/\+/g," "));
    </script>我能在 jscript 中找到這兩個函數的參考,它們在 javascript 中也一樣???在 jscript 中有的東西在javascript也有??? wsh只能用在jscript中吧,不能用在javascript中吧???replace(/\+/g," "))是什麼意思??煩請您回答!!
      

  6.   

    http://www.blueidea.com/bbs/newsdetail.asp?id=523379
    里有个urldecoding