Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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
Javascript 函数GetURLParameter(sParam)返回%20作为第页上的空白_Javascript_Jquery - Fatal编程技术网

Javascript 函数GetURLParameter(sParam)返回%20作为第页上的空白

Javascript 函数GetURLParameter(sParam)返回%20作为第页上的空白,javascript,jquery,Javascript,Jquery,我有一段代码将URL参数拉入登录页,问题是它将空格拉入%20。因此,如果我的url参数为: example.com/?title=我的网站它将在页面上显示我的%20网站。我希望它在不显示%20的情况下显示我的网站。这是密码 function GetURLParameter(sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split(

我有一段代码将URL参数拉入登录页,问题是它将空格拉入%20。因此,如果我的url参数为: example.com/?title=我的网站它将在页面上显示我的%20网站。我希望它在不显示%20的情况下显示我的网站。这是密码

function GetURLParameter(sParam)
   {   
     var sPageURL = window.location.search.substring(1);
     var sURLVariables = sPageURL.split('&');
     for (var i = 0; i < sURLVariables.length; i++) 
  {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == sParam) 
    {
        return sParameterName[1];
    }
  }
  }

(function ($) {
// fire once DOM is loaded
$(document).ready(function() {
    // set the cookie name
    var cookie_name = 'node-title';
    // get the "phone" URL param
    var phone_number = GetURLParameter('title');
    // check if there is a phone number in the URL
    if (phone_number) {
        // set the cookie
        $.cookie(cookie_name, phone_number, { path: '/' });
    }
    // get the phone cookie value
    var phone_cookie = $.cookie(cookie_name);
    // check if there is a value set in the phone cookie
    if (phone_cookie) {
        // swap the phone number
        $('.' + cookie_name).html(phone_cookie);
        // update the href too
        $('a.' + cookie_name).attr('href', 'tel://' + phone_cookie);
    }
    });
    })(jQuery);
函数GetURLParameter(sParam) { var sPageURL=window.location.search.substring(1); var sURLVariables=sPageURL.split('&'); 对于(变量i=0;i返回前只需对值进行url解码即可。替换

return sParameterName[1];


您看到的文本称为
url编码的
。您只需在显示之前对其进行解码。您可以将
GetURLParameter()
函数更改为:

function GetURLParameter(sParam)
   {   
     var sPageURL = window.location.search.substring(1);
     var sURLVariables = sPageURL.split('&');
     for (var i = 0; i < sURLVariables.length; i++) 
  {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == sParam) 
    {
        return return decodeURIComponent(sParameterName[1]);
    }
  }
}
函数GetURLParameter(sParam) { var sPageURL=window.location.search.substring(1); var sURLVariables=sPageURL.split('&'); 对于(变量i=0;i 如果您有兴趣了解有关不同
url编码的
组件的更多信息,请查看以下链接:

function GetURLParameter(sParam)
   {   
     var sPageURL = window.location.search.substring(1);
     var sURLVariables = sPageURL.split('&');
     for (var i = 0; i < sURLVariables.length; i++) 
  {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == sParam) 
    {
        return return decodeURIComponent(sParameterName[1]);
    }
  }
}