Javascript 函数GetURLParameter(sParam)返回%20作为第页上的空白
我有一段代码将URL参数拉入登录页,问题是它将空格拉入%20。因此,如果我的url参数为: example.com/?title=我的网站它将在页面上显示我的%20网站。我希望它在不显示%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(
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;ireturn 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;iurl编码的组件的更多信息,请查看以下链接:
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]);
}
}
}