JavaScript encodeURIComponent() 函數

來源:互聯網
上載者:User

標籤:

http://www.w3school.com.cn/jsref/jsref_encodeURIComponent.asp

 

定義和用法

encodeURIComponent() 函數可把字串作為 URI 組件進行編碼。

文法
encodeURIComponent(URIstring)
參數 描述
URIstring 必需。一個字串,含有 URI 組件或其他要編碼的文本。
傳回值

URIstring 的副本,其中的某些字元將被十六進位的逸出序列進行替換。

說明

該方法不會對 ASCII 字母和數字進行編碼,也不會對這些 ASCII 標點符號進行編碼: - _ . ! ~ * ‘ ( ) 。

其他字元(比如 :;/?:@&=+$,# 這些用於分隔 URI 組件的標點符號),都是由一個或多個十六進位的逸出序列替換的。

提示和注釋

提示:請注意 encodeURIComponent() 函數 與 encodeURI() 函數的區別之處,前者假定它的參數是 URI 的一部分(比如協議、主機名稱、路徑或查詢字串)。因此 encodeURIComponent() 函數將轉義用於分隔 URI 各個部分的標點符號。

 

encodeURI or encodeURIComponent

It depends on what you are actually wanting to do.

encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it.

encodeURIComponent will encode everything with special meaning, so you use it for components of URIs such as

var world = "A string with symbols / characters that have special meaning?";var uri = ‘http://example.com/foo?hello=‘ + encodeURIComponent(world);

JavaScript encodeURIComponent() 函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.