1

当用户单击特定框时,我想显示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>";
4

2 回答 2

0

您的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>;
于 2013-09-02T13:31:58.280 回答
-1

使用 javascript 设置为 jstl 变量值

<script>
    function function1()
    { 
        <c:set var="temp" value=""/>
        temp="Hello";
        alert(temp);   
    }
</script>
于 2015-03-02T05:40:23.720 回答