[英]how to pass parameter to a javascript function using struts taglib?
I have a javascript function updateHiddenField(value)
that gets a value as parameter and then sets this value as the value of a hidden field. 我有一个JavaScript函数
updateHiddenField(value)
,该函数获取一个值作为参数,然后将该值设置为隐藏字段的值。
I have a JavaBean flight
with parameters id
and flightNo
. 我有一个JavaBean
flight
,其参数为id
和flightNo
。
Problem: How can I pass the parameter id
of JavaBean flight
to the js function updateHiddenField(value)
when using <html:link>
tag(struts)? 问题:使用
<html:link>
标签(struts)时,如何将JavaBean flight
的参数id
传递给js函数updateHiddenField(value)
)?
<html:link href="javascript:updateHiddenField(idToPassHere)"><bean:write name="flight" property="flightNo"/></html:link>
Thanks Umar 谢谢乌玛
You don't seem to be gaining anything by using <html:link>
over <a>
- so that would be the easiest change: 通过在
<a>
使用<html:link>
似乎并没有获得任何<a>
-这将是最简单的更改:
<a href="javascript:updateHiddenField(<bean:write name="flight" property="id"/>)">
<bean:write name="flight" property="flightNo"/>
</a>
<a href="javascript:updateHiddenField(<bean:write name="flight" property="id"/>)">
<bean:write name="flight" property="flightNo"/>
<a href="javascript:updateHiddenField(<bean:write name="flight" property="id"/>)">
<bean:write name="flight" property="flightNo"/>
<a href="javascript:updateHiddenField(<bean:write name="flight" property="id"/>)">
<bean:write name="flight" property="flightNo"/>
</a>
More generally I would suggest you add event listeners to your DOM objects, rather than mixing markup & functionality. 更一般地说,我建议您将事件侦听器添加到DOM对象,而不是混合使用标记和功能。
<html:link href="javascript:updateHiddenField(<s:property value="id"/>)"><bean:write name="flight" property="flightNo"/></html:link>
假设您的taglib导入为<% @taglib prefix="s" uri="/struts-tags" %>
taglib <% @taglib prefix="s" uri="/struts-tags" %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.