简体   繁体   中英

JSP- How to pass parameters between quotes calling a javascript function

I have this snippet

            <c:forEach var="var" items="${selects.listOfVar}">
                <script>
                addIncFromSelect("param1","param2", "'" +${var} +"'");
                </script>
        </c:forEach>

What I would like to obtain is to call the "addIncFromSelect" function passing three parameters as string. The problem I have right now with the code is that the third value is passed like

"'" + foo +"'"

instead of

"foo"

I also tried this:

<c:forEach var="var" items="${selects.listOfVar}">
    <script>
    addIncFromSelect("param1","param2", ${var});
    </script>
</c:forEach>

but in this way is passed

foo

and it's not working either

I've found the solution. This seem to work

<c:forEach var="varTemp" items="${selects.listOfVar}">
    <c:set var="var" value="'${varTemp}'"/>
    <script>
    addIncFromSelect("param1","param2", ${var});
    </script>
</c:forEach>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM