我想将/ index页面(属性地址)和(email)上输入的文本数据传递到/注册页面。
问题:
查询字符串正在移动到URL中,但是如何使用URL中提供的文本数据填充/注册页面上的相应字段?
www.juwai.kiwi
<script>
(function(f, e, t){
initForm(f, e, t);
}(document.forms[0],'full_name',document.getElementsByName('full_name').valueOf()));
</script>
<script>
function initForm(oForm, element_name, init_txt) {
frmElement = oForm.elements[element_name];
frmElement.value = init_txt;
};
var queryStrng = [
{
full_name: "dave",
email: "email@to.do",
property_address: "prop address to do"
}
];
//queryStrng[0].full_name = document.getElementsByName("full_name").valueOf();
//var oFormObject = document.forms[0];
</script>
答案 0 :(得分:0)
尝试此功能:
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];
}
}
}
And this is how you can use this function assuming the URL is,
http://www.juwai.kiwi/sign-up.html?property_address=abcd&email=myemail%40gmail.com
var property_address = GetURLParameter('property_address');
var email = GetURLParameter('email');`