删除URL查询字符串中的加号(+)

编程入门 行业动态 更新时间:2024-10-11 17:21:50
本文介绍了删除URL查询字符串中的加号(+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试获取以下网址中的字符串以显示在我的网页上。

I am trying get the string in the following URL to display on my webpage.

example?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.

更多推荐

删除URL查询字符串中的加号(+)

本文发布于:2023-07-14 20:09:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106730.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加号   字符串   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!