我在 JS 函数中使用了 struts 标签,即
var ptp = "<c:out value='${myFormBean.myVar[0]}'/>";
它通过从适当的bean中获取正确的值,但我必须将它用于使用循环显示的多行,这就是为什么我在函数中发送行索引,但是当我尝试将该变量放入上面的行时,例如
function myFucn(ind){
var ptp = "<c:out value='${myFormBean.myVar[ind]}'/>";// this does not show any thing
//OR
var ptp = "<c:out value='${myFormBean.myVar['+ind+']}'/>";//This beaks the HTML
//OR
var ptp = "<c:out value='${myFormBean.myVar["+ind+"]}'/>";//This beaks the HTML
}
请帮助如何使用索引作为变量从上述标记中获取值。 提前致谢。
最佳答案
JavaScript is a code running in the Client side, It will only be functional when the Code is executed, I mean Called using a function or Some.!! So i believe its not possible to get the values in the JavaScript from the struts Tag..!!
可能的方法是将值作为参数传递,您可以传递值 使用
myFucn(indValue,'<c:out value='${myFormBean.myVar[ind]}'/>','<c:out value='${myFormBean.myVar['+ind+']}'/>','<c:out value='${myFormBean.myVar["+ind+"]}'/>')
通过这个,您的函数将在脚本函数中接收该值。
关于java - 如何在 JavaScript 中使用 struts taglib 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18503264/