简体   繁体   中英

JavaScript function arg into JSTL

  1. is there a way to move a javascript function-arg into JSTL tag?

     function loadList(listName) { <c:forEach var="item" items="${listName}">.... }
  2. Why did this code"

     x = '${item.category}';

    work all good and suddenly it didn't work, but change to

    x = "${item.category}";

    does work? I did alert( message ) in page load to check if the page load success.

I don't think it is possible to put a javascript variable into a JSTL tag without a "postback" or reload of the page. However, the reverse (ie, putting a JSTL tag value into a javascript variable) should be possible.

The reason is the separation between server-side (JSTL) and client-side (Javascript) code.

  • With 1st question as what I know, you cant. Instead the reverse of it as your example in 2nd question. As what @jordan mentioned.
  • In your 2nd question, I'm not sure why, may be you pass a value with ' or single qout on the list.category .

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