Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取URL删除+;_Url - Fatal编程技术网

获取URL删除+;

获取URL删除+;,url,Url,我的网址 print.html?name=Bentley+Foong&b=1&c=2 <script type='text/javascript'> var name = (location.search.split('name=')[1]||'').split('&')[0]; document.getElementById("print_to").innerHTML = name; </script> 变量名称=(location.search.split

我的网址 print.html?name=Bentley+Foong&b=1&c=2

<script type='text/javascript'>
var name = (location.search.split('name=')[1]||'').split('&')[0];
document.getElementById("print_to").innerHTML = name;
</script>

变量名称=(location.search.split('name='))[1]| |''''。split('&')[0];
document.getElementById(“print_to”).innerHTML=name;
我的HTML秀结果:Bentley+Foong

如何删除此“+”


谢谢。

您可以做一个非常简单的替换

var name = (location.search.split('name=')[1]||'').split('&')[0];
name = name.replace("+", " ");

尝试此函数从URL获取参数值

function\uuu通过名称(name)获取参数{
名称=名称。替换(/[\[]/,“\\\[”)。替换(/[\]]/,“\\\]”);
var regex=new RegExp(“[\\?&]”+name+“=([^&\]*)”,
results=regex.exec(location.search);
返回结果==null?”:decodeURIComponent(结果[1]。替换(/\+/g,”);

}

javascript中的字符串具有
replace
方法。