获取URL删除+;
我的网址 print.html?name=Bentley+Foong&b=1&c=2获取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
<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
方法。