我在主页上有一个表单,并试图将输入字段值传递到另一个仅在客户端使用的页面。问题是,我想在运行函数之前将传递的值重新显示回另一个表单字段,但我似乎无法使用 REGEX 替换“+”字符(也想保持间距)。知道如何在没有太多控制的情况下完成此任务吗?
第 1 页表格:
<form id="dlrhpform" type="GET" action="/dealer-locator">
<div id="hp-form-input">
<div style="padding-left:20px;">
<p>Enter address or zip code:</p>
<input style="float:left;" type="text" id="hpaddress" name="hpaddress"/>
</div>
</div>
<a href="javascript:;" onmouseover="MM_swapImage('hpsubmitbtn','','/btn_go_on.png',1)" onmouseout="MM_swapImgRestore()" />
<input onClick="_gaq.push(['_setAccount', 'UA-XXXXXXX-1'],['_trackEvent','Dealer Locator','Input Parameter', document.getElementById('hpaddress').value]);" style="position:relative; z-index:9999;" type="image" id="hpsubmitbtn" src="/btn_go.png" border="0" width="20" height="21" alt="hpsubmitbtn"/>
</form>
第二页表格:
<form name="user-location" id="user-location" method="post" action="#">
<div id="form-input" name="form-input">
<label for="address">Enter Address or Zip Code:</label>
<input type="text" id="address" name="address" style="width:200px;"/>
</div>
<div id="submit-btn"><input name="fetch" type="image" src="/searchbutton.png" onclick="address.value=address.value.replace(/,/g,''); _gaq.push(['_setAccount', 'UA-XXXXXXX-1'],['_trackEvent','Dealer Locator','Input Parameter', document.getElementById('address').value]);"/></div>
</form>
第二页脚本:
//Return Home Page Address From URL
var urladdress;
if(document.URL.indexOf("hpaddress") >= 0)
{
function getParams()
{
var idx = document.URL.indexOf('?');
parent.params = new Array();
if (idx != -1)
{
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++)
{
nameVal = pairs[i].split('=');
parent.params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
urladdress = unescape(params["hpaddress"]);
}
window.onload = function()
{
if(typeof urladdress !== 'undefined')
{
document.getElementById("address").value = urladdress;
}
};