最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Access velocity variable with javascript - Stack Overflow

programmeradmin1浏览0评论
<head> #set($test = "works")) </head>

<script> 
    var get = "${test}"; // I also tried using '$test' and "$test" also

    alert(get);
</script> 

And it alerts out ${test}, but should print works.

How can I get it to work?

<head> #set($test = "works")) </head>

<script> 
    var get = "${test}"; // I also tried using '$test' and "$test" also

    alert(get);
</script> 

And it alerts out ${test}, but should print works.

How can I get it to work?

Share Improve this question edited Jul 2, 2012 at 9:18 Jaanus asked Jul 2, 2012 at 9:07 JaanusJaanus 16.5k52 gold badges149 silver badges204 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 8

try this...

    #set ($test = "works")

  <script type="text/javascript">
       var myvar = "${test}";
       alert (myvar);
  </script>

THIS WORKS SURELY!!!!

Try var get = "$test"; instead of var get = "${test}";

I realize the question is old, but this worked for me:

#set ($test = "hi")
<script>
    alert("$test");
</script>

Need to include quotes around the variable in the alert since it is a string.

I had that problem while using tiles, the only way i got it to work was to use the jstl c:out tag, like:

var get = "<c:out value='${test}' />";

that should work, and remember to add the jstl include on the top of the page

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

Just use it as in html:

<script> 
    var get = $test;

    alert(get);
</script> 
发布评论

评论列表(0)

  1. 暂无评论