删除URL查询字符串中的加号(+)
我正在尝试获取以下网址中的字符串以显示在我的网页上。
I am trying get the string in the following URL to display on my webpage.
http://example.com?ks4day=Friday+September+13th
编辑: 当我的CRM程序合并URL时,URL中的日期会因人而异。
The date in the URL will change from person to person as it's merged in by my CRM program.
我可以使用以下内容在我的网页上显示它下面的代码,问题是加号(+)也是如此。
I can get it to display on my webpage using the code below, the problem is the plus signs (+) come through as well.
例如。周五+ 9月+ 13日
eg. Friday+September+13th
我需要做的是用空格替换加号(+),看起来像这样:
What I need it to do is replace the plus signs (+) with spaces so it looks like this:
例如。 9月13日星期五
eg. Friday September 13th
我是新来的,所以我在解决这个问题上遇到了一些麻烦。
I'm new to this so I'm having some trouble working it out.
任何帮助都将不胜感激。
Any help would be appreciated.
这是我在a中使用的代码。 js文件
function qs(search_for) {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0 && search_for == parms[i].substring(0,pos)) {
return parms[i].substring(pos+1);;
}
}
return "";
}
这是我在我的网页上使用的代码它显示
<script type="text/javascript">document.write(qs("ks4day"));</script>
如果你正在做什么,加号将不是唯一会给你带来困难的人。撇号('),等于(=),加上(+),基本上不在允许的URL字符中的任何内容(参见百分比编码 @维基百科)将被逃脱。
If that's what you are doing, the plus sign will not be the only one that is going to give you a hard time. The apostrophe ('), equals (=), plus (+) and basically anything not in the permitted URL characters (see Percent-encoding @ Wikipedia) is going to get escaped.
你要找的是 decodeURIComponent 功能。
What you are looking for is the decodeURIComponent function.