我有一个网址如下
https://example.com/#registration-update?gigya=true&socialProvider=yahoo&gigyaUID=_guid_59DUvJro84GQM2B_o-SjcoWyforCmmvGQYVdMX1yhtlYImE_62mKDUWiUtPo0cxp&lastName=Jackson&firstName=peter&email=peter2015@ymail.com&zip=
我从 url 中获取值并在表单提交时填充表单我应该清除值并将 url 设置为https://example.com/
如何使用jquery做到这一点请帮助
要获取我使用 jquery 的值,如下所示。
var username = getUrlVars()["firstName"];
var lastname = getUrlVars()["lastName"];
var email = getUrlVars()["email"];
var zipcode = getUrlVars()["zip"];
$('#regi_firstname').val(username);
$('#regi_lastname').val(lastname);
$('#regi_user_email').val(email);
$('#regi_confirmemail').val(email);
$('#zip').val(zipcode);
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}