使用 javascript 选择 s:select 值
我在jsp中有一个迭代器,迭代器包含2个列表:
<s:iterator value="reportNamesList">
<s:select name="hour" listKey="codeDesc" listValue="code" list="hourList" />
<s:select name="minute" listKey="codeDesc" listValue="code" list="minutesList" />
</s:iterator>
现在我的要求是,当选择小时值(比如10)时,分钟下拉值也应该变成10。
我正在使用javascript。请建议如何做。
I have an iterator in jsp and the iterator contains 2 lists:
<s:iterator value="reportNamesList">
<s:select name="hour" listKey="codeDesc" listValue="code" list="hourList" />
<s:select name="minute" listKey="codeDesc" listValue="code" list="minutesList" />
</s:iterator>
Now my requirement is that when hour value is selected (say as 10), the minute dropdown value should also become 10.
I am using javascript. Kindly suggest how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Naved 是正确的;您可以像其他任何元素一样与标记生成的 DOM 元素进行交互(尽管我会使用 jQuery 并为自己节省大量时间)。您可以使用
id
元素显式设置 id。在您的情况下,由于您将有多组选择框,因此您需要根据
reportNamesList
中唯一的内容(可能是一个 id)创建 id。那么,您的id
属性可能类似于id="hours_%{id}
或者如果您使用
的var
属性,id=hours_%{#foo.id}
您的 JavaScript 需要将每个小时选择绑定到其关联的分钟选择。
@Naved is correct; you interact with tag-produced DOM elements the same way as any other (although I'd use jQuery and save yourself a lot of time). You can explicitly set an id by using the
id
element.In your case, since you'll have multiple groups of select boxes, you'll need to create the id based on something unique in the
reportNamesList
, perhaps an id. Yourid
attribute, then, would probably look something likeid="hours_%{id}
or if you use the<s:iterator>
'svar
attribute,id=hours_%{#foo.id}
.Your JavaScript would need to bind each hours select to its associated minutes select.
该代码似乎是在 Struts2 中编码的。虽然我不太清楚,但我发现为这些类型的框架编写任何 JavaScript 的最简单方法是
etElementById('selHour')
或getElementsByName('selHour')
编写 javascript 代码并完成您的工作。我希望这将帮助您提供正确的输出。
The code seems that you are coding it in Struts2. Although I am not very much aware of it but the simplest way I found to write any javascript for these types of framework is
etElementById('selHour')
orgetElementsByName('selHour')
and do your stuff.I hope this will help you to give the proper output.