Struts2 param 标签与 javascript
我是 Struts2 的新手,但已经为一个问题苦苦挣扎了 2 天。
基本上,我想在
中设置一个
标记,其中包含页面其他位置的 div 标记的内容。
<div id="div1">My value</div>
<s:url action="myAction" var="url">
<s:param name="param1">...content of div1...</s:param>
</s:url>
当我尝试在
标记中嵌入一些 javascript 调用时,不会评估 javascript 调用。
我的问题是:有没有办法在评估时将 javascript 调用绑定到
标记?
多谢
I'm new to Struts2 but have been struggling with a problem for 2 days now.
Basically, I want to set up an <s:param>
tag within an <s:url>
with the content of a div tag somewhere else in the page.
<div id="div1">My value</div>
<s:url action="myAction" var="url">
<s:param name="param1">...content of div1...</s:param>
</s:url>
When I tried to embed some javascript call within <s:param>
tags, javascript calls are not evaluated.
My question is : Is there a way to bind a javascript call to an <s:param>
tag whenever it is evaluated ?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,使用
标记是不可能的,因为该标记是在页面提供给用户之前呈现的(即,它必须先填充链接,然后再将其发送到 JavaScript 所在的浏览器)可以接管)。不过,您想要做的事情可以通过负载处理程序来实现。下面是如何实现它的 jQuery 示例:
如果您使用 Struts 填充要用作链接参数的
,另一种选择是将其捕获在变量中在渲染链接之前,然后直接在
标记中使用它:Unfortunately it's not possible with the
<s:param>
tag because this tag is rendered before the page is served to the user (i.e. it has to populate the link before it makes it to the browser where Javascript can take over).What you're trying to do would be possible with a load handler though. Below is a jQuery example of how you could accomplish it:
Another option if you're using Struts to populate the
<div>
you want to use as a link param would be to capture that in a variable before you render the link and then use it directly in the<s:param>
tag: