0

我在事件 onClick 上调用此函数

function openGrpLifeStmtReport (busnsourceid,treatyId,policyid,productid,schemename,periodfrom,periodto,plcyeffdtfrom,polcyeffto,benType,exportTo,jasperName,jasperNamesum,reportvar1,reportvar2,reportvar3,reportvar4,userloged,clientId)
{

    document.getElementById("reportvar1").value = document.getElementById("busnsourceid").value;
    document.getElementById("reportvar2").value = document.getElementById("treatyId").value;
    document.getElementById("reportvar4").value = document.getElementById("productid").value;
    var Busnsourceid=document.getElementById(busnsourceid).value;
    var TreatyID=document.getElementById(treatyId).value;
    var PolicyID=document.getElementById(policyid).value;
    var ProductID=document.getElementById(productid).value;
    var SchemeName=document.getElementById(schemename).value;
    var PeriodFrom=document.getElementById(periodfrom).value;
    var PeriodTo=document.getElementById(periodto).value; 
    var plcyeffdtfrom=document.getElementById(plcyeffdtfrom).value;
    var polcyeffto=document.getElementById(polcyeffto).value;
    var BenType=document.getElementById(benType).value;
    var exportTo=document.getElementById(exportTo).value;
    var jasperName=document.getElementById(jasperName).value; 
    var jasperNamesum=document.getElementById(jasperNamesum).value; 
    var userloged=document.getElementById(userloged).value;
    var clientId=document.getElementById(clientId).value;
    var reportvar3; 
    var disorderby = document.getElementById("orderBy").value;
    var disgroupby = document.getElementById("groupBy").value;
            for (var form=0; form < document.forms.length; form++) 
        {
         var what = document.forms[form];
         for (var i=0, j=what.elements.length; i<j; i++) 
         {
           if (what.reportvar3[i].checked == true) 
            {
                reportvar3 = what.reportvar3[i].value;          
                break;  
            }
         } 
        }

        var url = "./GroupLifeAdvRep.do?action=customAction&innerAction=printGrpLifeRep&CedantCode="+Busnsourceid+"&TreatyID="+TreatyID+
            "&Policy Id="+PolicyID+"&ProductID="+ProductID+"&SchemeName="+SchemeName+"&PeriodFrom="+PeriodFrom+"&PeriodTo="+PeriodTo+"&plcyeffdtfrom="+plcyeffdtfrom+"&polcyeffto="+polcyeffto+"&BenType="+BenType+"&exportTo="+exportTo+"&jasperName="+jasperName+"&jasperNamesum="+jasperNamesum+"&reportvar1="+reportvar1+"&reportvar2="+reportvar2+"&reportvar3="+reportvar3+"&reportvar4="+reportvar4+"&disorderby="+disorderby+"&disgroupby="+disgroupby+"&userloged="+userloged+"&clientId="+clientId;
        window.open(url,"target","width=850, height=600, top=75, left=75, toolbar=0, menubar=0, location=0, status=0, scrollbars=1, resizable=1");

}

调用此函数的代码

<a href="#"><img src="Images/generatereport_btn.gif" alt="generatereport" border="0" onclick="openGrpLifeStmtReport('busnsourceid','treatyId','policyid','productid','schemename','periodfrom','periodto','plcyeffdtfrom','polcyeffto','benType','exportTo','jasperName','jasperNamesum','reportvar1','reportvar2','reportvar3','reportvar4','userloged','clientId')"/></a> 
4

1 回答 1

2

问题:

  1. IE 允许在只有 NAME 的字段上调用 ​​getElementById,其他浏览器不允许这样做,因此请确保表单字段具有 ID
  2. 您在链接中调用此图像的 onclick。不是推荐的方式。使用链接的 onclick 并返回 false
  3. OPEN 参数中的空格 - 它们可能会破坏某些浏览器中的内容 - 也target可能是保留字

function openGrpLifeStmtReport (busnsourceid,treatyId,policyid,productid,schemename,periodfrom,periodto,plcyeffdtfrom,polcyeffto,benType,exportTo,jasperName,jasperNamesum,reportvar1,reportvar2,reportvar3,reportvar4,userloged,clientId) {

document.getElementById("reportvar1").value = document.getElementById("busnsourceid").value;
document.getElementById("reportvar2").value = document.getElementById("treatyId").value;
document.getElementById("reportvar4").value = document.getElementById("productid").value;
var Busnsourceid=document.getElementById(busnsourceid).value;
var TreatyID=document.getElementById(treatyId).value;
var PolicyID=document.getElementById(policyid).value;
var ProductID=document.getElementById(productid).value;
var SchemeName=document.getElementById(schemename).value;
var PeriodFrom=document.getElementById(periodfrom).value;
var PeriodTo=document.getElementById(periodto).value; 
var plcyeffdtfrom=document.getElementById(plcyeffdtfrom).value;
var polcyeffto=document.getElementById(polcyeffto).value;
var BenType=document.getElementById(benType).value;
var exportTo=document.getElementById(exportTo).value;
var jasperName=document.getElementById(jasperName).value; 
var jasperNamesum=document.getElementById(jasperNamesum).value; 
var userloged=document.getElementById(userloged).value;
var clientId=document.getElementById(clientId).value;
var disorderby = document.getElementById("orderBy").value;
var disgroupby = document.getElementById("groupBy").value;

var reportvar3=""; 
var reportvars = document.getElementsByName("reportvar3");
for (var i=0; i < reportvars.length; i++) {
  if (reportvars[i].checked) {
    reportvar3 = reportvars[i].value;          
    break;  
  } 
}

var url = "./GroupLifeAdvRep.do?action=customAction&innerAction=printGrpLifeRep&CedantCode="+Busnsourceid+"&TreatyID="+TreatyID+
        "&Policy Id="+PolicyID+"&ProductID="+ProductID+"&SchemeName="+SchemeName+"&PeriodFrom="+PeriodFrom+"&PeriodTo="+PeriodTo+"&plcyeffdtfrom="+plcyeffdtfrom+"&polcyeffto="+polcyeffto+"&BenType="+BenType+"&exportTo="+exportTo+"&jasperName="+jasperName+"&jasperNamesum="+jasperNamesum+"&reportvar1="+reportvar1+"&reportvar2="+reportvar2+"&reportvar3="+reportvar3+"&reportvar4="+reportvar4+"&disorderby="+disorderby+"&disgroupby="+disgroupby+"&userloged="+userloged+"&clientId="+clientId;
window.open(url,"_blank","width=850,height=600,top=75,left=75,scrollbars,resiza‌​ble");
return false; // cancel link            
}

调用此函数的代码

<a href="#" onclick="return openGrpLifeStmtReport('busnsourceid','treatyId','policyid','productid','schemename','periodfrom','periodto','plcyeffdtfrom','polcyeffto','benType','exportTo','jasperName','jasperNamesum','reportvar1','reportvar2','reportvar3','reportvar4','userloged','clientId')"><img src="Images/generatereport_btn.gif" alt="generatereport" border="0" /></a> 
于 2013-08-06T13:01:05.027 回答