[英]How to set the JSTL variable value through javascript variable
我想在用戶單擊特定框時顯示html代碼。
當用戶從可用選項之一中選擇一個值時,將調用一個 JavaScript 函數,該函數將所選值存儲在一個變量中。
我在實現代碼以將EL變量的值與innerHTML變量進行比較時遇到困難。
以下是我目前使用的代碼:
var groupid = parseInt($('#selectgroup').val());
document.getElementById("facilityTable").innerHTML= "<c:forEach var='group'
items='${groups}'>"+
"<c:if test='${group.key == (groupid)}'>"+
"<td>+Test+${group.value.groupName}</td>"+
"<td>${group.value.groupId}</td>" +
"</c:if>"+
"</c:forEach>";
你的JSTL標簽不會是JS輸出的一部分,所以沒有理由把它們放在引號中,例如:
document.getElementById("facilityTable").innerHTML= ""
<c:forEach var='group' items='${groups}'>
<c:if test='${group.key == (groupid)}'>
+ "<td>+Test+${group.value.groupName}</td>"+
"<td>${group.value.groupId}</td>"
</c:if>
</c:forEach>;
使用 javascript 設置為 jstl 變量值
<script>
function function1()
{
<c:set var="temp" value=""/>
temp="Hello";
alert(temp);
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.