我有一个基于 Spring Web 模型- View - Controller (MVC) 框架的项目。 Spring Web模型- View - Controller (MVC)框架的版本是3.2.8,部署在WebLogic Server上版本:12.1.2.0.0 我的 JSP 中有这段代码
<script src="${contextPath}/scripts/jquery.min.js" type="text/javascript">
var optionsEUCountriesArray = [];
var optionsNonEUCountriesArray = [];
<c:forEach items="${countries}" var="country" varStatus="status">
var option${country.id} = new Option("${country.id}","${country.description}");
<c:choose>
<c:when test="${country.euMember}">
optionsArray.push(option${country.id});
</c:when>
<c:when test="${not country.euMember}">
optionsArray.push(option${country.id});
</c:when>
</c:choose>
</c:forEach>
</script>
<script src="${contextPath}/scripts/selectbox.js" type="text/javascript"></script>
在 selectbox.js
中,我使用变量 optionsEUCountriesArray
,但出现此错误
Uncaught ReferenceError: optionsEUCountriesArray is not defined
最佳答案
您正在组合脚本。也许这应该可以解决您的问题..
<script src="${contextPath}/scripts/jquery.min.js" type="text/javascript"> </script>
<script>
var optionsEUCountriesArray = [];
var optionsNonEUCountriesArray = [];
<c:forEach items="${countries}" var="country" varStatus="status">
var option${country.id} = new Option("${country.id}","${country.description}");
<c:choose>
<c:when test="${country.euMember}">
optionsArray.push(option${country.id});
</c:when>
<c:when test="${not country.euMember}">
optionsArray.push(option${country.id});
</c:when>
</c:choose>
</c:forEach>
</script>
关于Javascript - 在 JSP 中定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42691742/