首页 > 代码库 > JavaScript隐藏Url中的参数
JavaScript隐藏Url中的参数
<script type="text/javascript">
function submitForm(url, data)
{
var eleForm = document.body.appendChild(document.createElement(‘form‘));
eleForm.action = url;
for (var property in data)
{
var hiddenInput = document.createElement(‘input‘);
hiddenInput.type = ‘hidden‘;
hiddenInput.name = property;
hiddenInput.value = http://www.mamicode.com/data[property];
eleForm.appendChild(hiddenInput);
}
this.eleForm = eleForm;
if (!submitForm._initialized)
{
submitForm.prototype.post = function ()
{
this.eleForm.method = ‘post‘;
this.eleForm.submit();
};
submitForm._initialized = true;
}
}
function Onclick()
{
//location.href = "http://www.mamicode.com/Activity/ActivityInformation?a_id=" + "1"; // Url中会带有参数
new submitForm(‘/Activity/ActivityInformation‘, { a_id: "1" }).post(); // Url中的参数被隐藏
}
</script>
JavaScript隐藏Url中的参数