Forum

Yampiz Forum

Sharing let knowledge Spreaded, Reading let spirits growth, Creative let culture extended, Let us
  • 禁止廣告文
  • 知識傳播
  • 閱讀
  • 心靈成長
  • 創作
  • 文化傳承
Forum Dictionary / Programming / 網頁/網站程式 / JavaScript /

Javascript 中有沒有 PHP 的 urlencode 函式

New Subject
Random
Previous
Next
|
Javascript 中有沒有 PHP 的 urlencode 函式

我想在傳送的單位資料裡加入類似 PHP urlencode 的函式,先在 Javascript 再送到後端去,有大大知道 Javascript 有沒有相同功能的函式?
  • Keywords : 函式, Javascript, 相同功能, 大大, 傳送, urlencode
0 0
2008-11-26T18:57:15+0000

黑目狀態 :

之前找到的用Javascript 寫的替代函式:

<script language="javascript">
function UrlEncode(str){
  var ret="";
  var strSpecial="!"#$%&'()* ,/:;<=>?[]^`{|}~%";
  for(var i=0;i<str.length;i ){
   var chr = str.charAt(i);
    var c=str2asc(chr);
    tt = chr ":" c "n";
    if(parseInt("0x" c) > 0x7f){
      ret ="%" c.slice(0,2) "%" c.slice(-2);
    }else{
      if(chr==" ")
        ret =" ";
      else if(strSpecial.indexOf(chr)!=-1)
        ret ="%" c.toString(16);
      else
        ret =chr;
    }
  }
  return ret;
}
function UrlDecode(str){
  var ret="";
  for(var i=0;i<str.length;i ){
   var chr = str.charAt(i);
    if(chr == " "){
      ret =" ";
    }else if(chr=="%"){
     var asc = str.substring(i 1,i 3);
     if(parseInt("0x" asc)>0x7f){
      ret =asc2str(parseInt("0x" asc str.substring(i 4,i 6)));
      i =5;
     }else{
      ret =asc2str(parseInt("0x" asc));
      i =2;
     }
    }else{
      ret = chr;
    }
  }
  return ret;
}
</script>

0 0
2008-11-28T19:31:32+0000

魚戀秋波 Neil Y.K. :

其實可以用Javascript 提供的 escape() 這個函式就可以囉!
其他相關的函式還有 encodeURI 跟 decodeURI.
不同自己寫額外的函式唷!
0 0
2008-11-29T18:12:10+0000


  • Now, you can post comments by Facebook Account when your Yampiz account was logout or unvariable. whatever, we suggest to post comment by Yampiz Account to get more bounds to join new events of Heyxu
Comment
 
Verify

Facebook Page

QR-Code and APP Launcher

User Guide
This Webpage

In those service tabs, "Scan QRCode, in mobile device" or "Click the button, in this device" to open webpage or APP-related operations.
QRCode
  • Auto Platform
    For better browsing experience, it will auto detects your device to display webpage.
  • Bug Report
    Tell us about the idea, problem and errors you found.
  • Comodo Secure
    The sensitive data transmission adopts by SSL-2048 authenticated encryption.
  • Copyright
    © 2009 YamPiz Digital Inc. & Jaby Group. All rights reserved.
  • Revised Version
    V2.2.197
    29 Oct 2024 (GMT+8)