---
title: "JS在URL转码时遇到的加号问题"
author: "lfzhs"
date: "2010-03-22T14:59:13Z"
tags: []
categories: ["Web前端"]
slug: "js-url"
draft: false
lastmod: "2010-03-22T14:59:13Z"
id: 621349
url: "https://lfzhs.iteye.com/blog/621349"
---

URL参数中出现了半角的加号，因此需要转码。

相关JS函数有encodeURI()和encodeURIComponent()。根据MSDN的说法，使用了encodeURI()，无效，加号还是加号。

 

encodeURIComponent()是对所有的字符进行转码。根据MSDN的说法，它只是额外对“/”、“?”等字符进行了处理，并没有提到“+”字符。然而实验对比的结果，encodeURI()不处理半角加号，encodeURIComponent()处理。