我真的很想将您的代码重写为更惯用的 JavaScript。在此过程中,我发现 formBypassQueryString 变量从未被分配,这可能会导致问题。这是我的版本:
function showPatientInfo(pid) {
redirectToPage("Create_Order.aspx", "pid=" + pid);
return false;
}
function redirectToPage(pageName, queryString) {
if (pageName === "" || queryString === "") return;
var keyValues = queryString.split("&"),
form = createQueryStringForm(pageName);
for (var i = 0; i < keyValues.length; i++) {
var keyValue = keyValues[i].split("="),
field = createQueryStringField(keyValue[0], keyValue[1]);
form.appendChild(field);
}
form.submit();
}
function createQueryStringField(name, value){
var field = document.createElement('input');
field.setAttribute('type', 'hidden')
field.setAttribute('name', name)
field.setAttribute('value', value)
return field;
}
function createQueryStringForm(pageName){
var form = document.createElement('form');
form.setAttribute('id', 'form-bypass-query-string');
form.setAttribute('method', 'POST');
form.setAttribute('action', pageName);
return form;
}