如何将文本中的空格转移到新页面

How can I keep the space in text transferred to new page?

本文关键字:空格 转移 新页面 文本      更新时间:2023-09-26

当用户单击"下一步"按钮时,来自两个单独文本框的数据会转移到新页面,但应该有%20个空格。我该如何避免这种情况?

originalpage.html 中的内联javascript

$('#next').click(function(){
        var coachFullName = $('#coach_txt_box').val();
        var teamName = $('#team_txt_box').val();
        if(!!coachFullName){
window.location.href = 'newpage.html?zip=' + coachFullName + teamName;
        } else {
            $('# coach_txt_box').watermark('please enter coach name',{className: 'watermarkError'});
        }
    });

来自newpage.html 的内联javascript

function getParameterByName(name)
{
    name = name.replace(/['[]/, "'''[").replace(/[']]/, "''']");
    var regexS = "[''?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.search);
    if(results == null)
        return "";
    else
        document.signupform.coach_and_team_name.value = results[1];
        return decodeURIComponent(results[1].replace(/'+/g, " "));
}
getParameterByName('coach');

您应该使用以下内容php中的urldecode()decodeURIComponent()。。

regex不需要完成您想要的