javascript 如何通过javascript变量设置JSTL变量值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18574189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 12:26:38  来源:igfitidea点击:

How to set the JSTL variable value through javascript variable

javascriptjsp

提问by Dinesh Maske

I would like to display htmlcode when the user clicks on a particular box.

我想在用户单击特定框时显示html代码。

When the user selects a value from one of the available options, a JavaScript function is invoked which stores the selected value against a variable.

当用户从可用选项之一中选择一个值时,将调用一个 JavaScript 函数,该函数将所选值存储在一个变量中。

I am having difficulty with implementing code to compare the value of ELvariable with the innerHTMLvariable.

我在实现代码以将EL变量的值与innerHTML变量进行比较时遇到困难。

Below is the code I am currently using:

以下是我目前使用的代码:

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>";

回答by udalmik

Your JSTLtags will not be a part of JSoutput, so there is not reason to put them into quotes, e.g.:

你的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>;

回答by Gautam Viradiya

Set to jstl variable value using javascript

使用 javascript 设置为 jstl 变量值

<script>
    function function1()
    { 
        <c:set var="temp" value=""/>
        temp="Hello";
        alert(temp);   
    }
</script>