[英]Javascript - define variables in a JSP
我有一個基於Spring Web模型 - 視圖 - 控制器(MVC)框架的項目。 Spring Web模型 - 視圖 - 控制器(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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.