在我的jsp中,我有类似的东西


 <%
 String isMultipleOfficesExists =(String)request.getAttribute(“MultipleOfficesExists” );
 String isMultipleOfficeSecurity =(String)request.getAttribute(“MultipleOfficeSecurityExists”);
 String envParm =“default”;
 if(“true”.equals(isMultipleOfficesExists)){
 envParm =“multipleOffice”;
} else if(“true”.equals(isMultipleOfficeSecurity)){
 envParm =“multipleOfficeSecurity”;
}
%> 



 在我的表单底部,在我的提交按钮中,我正在调用JavaScript On-click功能。
& #xA;
 < input class =“white_button_extra_large”type =“button”value =“<%= goBtn%>” onclick =“javascript:selectEnvironment(envParm);”>



 我的脚本部分是:

 
 function selectEnvironment(envParm)
 {
 resetToken();
 logoutFlag = false;
 document.forms [0] .action = contextURL +'/ login / selectEnvironment?envParam ='+ envParm;
 document.forms [0] .submit();
}



 但是我得到 Uncaught ReferenceError:envParam未定义
如何解决此问题?

答案 0 :(得分:1)
在JSP中使您的envParm变量全局化。您的点击事件应如下所示
<input class="white_button_extra_large" type="button" value="<%=goBtn%>" onclick="javascript:selectEnvironment('<%=envParm%>')">
您应该从javascript函数传递值。参数应该有值。请参阅此链接Passing arguments