简体   繁体   English

如何获得标签的属性?

[英]How do I get the attributes of a tag?

Been looking everywhere, I just can't seen to find it (probably because I'm wording it wrong or something). 到处都在寻找,我只是看不到找到它(可能是因为我用错了字眼或其他措辞)。

In have a simple select tag in a from with several options. 在中有多个选项的简单选择标签。 Each option has an id attribute. 每个选项都有一个id属性。 I want to get the id from the selected options. 我想从所选选项中获取id

The name of the select tag is "group", so in the servlet I call: select标记的名称是“ group”,因此在servlet中我称之为:

String group = request.getParameter("group");

This only returns the "label" of the option (the name of it, what the user sees). 这仅返回选项的“标签”(名称,用户看到的内容)。 I don't want that, I want the id of it. 我不想要那个,我想要它的ID。 I tried 我试过了

String group = request.getParameterValues("group");

but that just returns an array with one item, the label of the option. 但这只是返回一个数组,其中包含一项,即选项的标签。

How can I do this? 我怎样才能做到这一点? Thanks. 谢谢。

You should set the value attribute of the option tag to what you want to get from servlet: 您应该将option标记的value属性设置为要从servlet获取的属性:

   <select name="parent">
     <c:forEach items="${parents}" var="parent">
       //      here set value="yourid"
       <option value="${parent.id}">${parent.name}
     </c:forEach>
   </select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM