如何将文本空间保留转移到新页面?

时间:2013-02-24 19:44:52

标签: javascript jquery regex firefox

当用户点击“下一步”按钮时,来自两个单独文本框的数据将传输到新页面,但是%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');

1 个答案:

答案 0 :(得分:-1)

你应该使用一些东西 php中的urldecode()decodeURIComponent() ..

正则表达式无需完成您想要的任务