如何将EL变量传递给javascript
我有一个变量 $ {bean.name}
如何将它传递给javascript var?我试过 var name =$ {bean.name}
和 var name = $ {bean.name}
但它不起作用。
I have a variable ${bean.name}
how can i pass it to a javascript var? I've tried var name = "${bean.name}"
and var name = ${bean.name}
but it does not work.
我的想法是把它放在一个隐藏的输入中,就像在隐藏的< input id =test中一样type =textvalue$ {bean.name}>
my idea is to put it in a hidden input like in a hidden <input id="test" type="text" value"${bean.name}">
var name = document.getElementById("test").value;
这不起作用 var name
成为字符串$ {bean.name}
this doen't work either var name
becomes the string "${bean.name}"
注意。我不能使用jstl
note. i can't use jstl
你不能在 .js评估JSTL
文件。仅在 .jsp
文件中。 (除非你重新映射jsp servlet,但我不建议这样做。)
You can't have JSTL evaluated in .js
files. Only in .jsp
files. (unless you remap the jsp servlet, but I wouldn't advise to do so).
更好的方法是在.jsp中定义变量,包括.js ,并将这些变量作为参数传递给初始化函数。
The better approach is to define the variables in the .jsp including the .js, and pass these variables as arguments to an initializing function.
还要确保没有 isELIgnored =true