当父窗口执行此方法:
function showWin(){
var retValue=new Array();
var url="/jsp/employee/employeeInfoList.jsp";
retValue=window.showModalDialog(url,'','dialogHeight:400px;dialogWidth:600px');
document.aform.employeeName.value=retValue[0];
document.aform.employeeId.value=retValue[1];
document.aform.team.value=retValue[2];
document.aform.telephone.value=retValue[4];
document.aform.costCenter.value=retValue[10];
}
后,将弹出路径为/jsp/employee/employeeInfoList.jsp的子窗口;
字窗口的程序:
function evalSave() {
var checks = getCheckedOnly(document.aform.chkIndex);
var until = checks.length;
for (var idx=0; idx < until; idx++) {
selectRow(checks[idx]);
}
}
function getCheckedOnly(inputs) {
var result = new Array();
if (inputs && inputs.tagName == "INPUT" && inputs.checked) result[0] = inputs;
else if (inputs && inputs.length && inputs.length > 0 ) {
var until = inputs.length;
for (var idx=0; idx<until; idx++) {
if (inputs[idx].tagName == "INPUT" && inputs[idx].checked) result[result.length] = inputs[idx];
}
}
return result;
}
function selectRow(radio){
var oTR = findParentTag(radio, "TR");
var name = findTagByName(oTR, "input", "name").value;
var nameCn = findTagByName(oTR,"input","nameCn").value;
var employeeId = findTagByName(oTR, "input", "employeeId").value;
var teamName = findTagByName(oTR, "input", "teamName").value;
var email = findTagByName(oTR, "input", "email").value;
var officeTel = findTagByName(oTR, "input", "officeTel").value;
var tel = findTagByName(oTR, "input", "tel").value;
var departmentName = findTagByName(oTR, "input", "departmentName").value;
var gradeEn = findTagByName(oTR, "input", "gradeEn").value;
var grade = findTagByName(oTR, "input", "grade").value;
var costCenter=findTagByName(oTR, "input", "costCenter").value;
var myArray=new Array();
myArray[0]=name;
myArray[1]=employeeId;
myArray[2]=teamName;
myArray[3]=email;
myArray[4]=officeTel;
myArray[5]=tel;
myArray[6]=departmentName;
myArray[7]=gradeEn;
myArray[8]=grade;
myArray[9]=nameCn;
myArray[10]=costCenter;
returnValue = myArray;
window.close();
}
function findParentTag(oTag, tagName) {
while (oTag && oTag.tagName != "BODY") {
if (oTag.tagName == tagName) return oTag;
oTag = oTag.parentNode;
}
return null;
}
function findTagByName(oTag, tagName, name) {
var tags = oTag.getElementsByTagName(tagName);
for (var idx=0; idx<tags.length; idx++) {
if (tags[idx].name == name) return tags[idx];
}
return null;
}
这样就把字窗口中选中的一条记录返回到父窗口中,并放到相应的input中。