日期:2014-05-18  浏览次数:20589 次

html:select的取值问题
我用的struts架构
jsp页面中:
<html:select   property= "interesting "     multiple= "true ">
<html:option   value= "htmlselect.sing "> Sing </html:option>
<html:option   value= "htmlselect.print "> Print </html:option>
<html:option   value= "htmlselect.film "> Film </html:option>
<html:option   value= "htmlselect.computerGame "> Computer   Game </html:option>
<html:option   value= "htmlselect.other "> Other </html:option>
</html:select>
可以多选,对应的form中,我定义了一个与之对应的数组,可以自动获得值,问题是
自动获得的是我选中的value值,如:htmlselect.print,而我想要的是显示的文本值,如何得到呢。不能把value和显示文本写成一样的。
高手指点一下,分不多了,多谢。

------解决方案--------------------
html:select获得的只能是value
------解决方案--------------------
同意楼上的,只能取value,把文本值写到资源文件,通过key来取得
------解决方案--------------------
首先用了struts的tag问题变得很简单了

<html:select size= "1 " styleClass= "scrolltext " name= "FolderManagerForm " property= "avaiableFolder " style= "width=100% " onchange= "parentChange();return false; ">
<html:options name= "FolderManagerForm " labelProperty= "dropFolderNameList " property= "dropFolderList " />
</html:select>

这个就是标准的struts的实现方式
<html:select 中:
name= "FolderManagerForm " 你的form的名字
property= "avaiableFolder " 你改为“interesting”

<html:options 中:
name= "FolderManagerForm " 你的form的名字
labelProperty= "dropFolderNameList "
property= "dropFolderList "

property,labelProperty 分别对应你下拉列表的List值。

property 在form中是一个ArrayList。用来表示code
labelProperty 在form中是一个ArrayList。用来表示名称
比如问题中
value= "htmlselect.sing "> Sing </html:option>
<html:option value= "htmlselect.print "> Print </html:option>
<html:option value= "htmlselect.film "> Film </html:option>
<html:option value= "htmlselect.computerGame "> Computer Game </html:option>
<html:option value= "htmlselect.other "> Other </html:option>

可以把Sing,Print。。。。。 放到一个ArrayList中,然后通过 labelProperty 表示出来



------解决方案--------------------
<body>
<form>
<select name= "select1 ">
<option value= "v1 "> l1 </option>
<option value= "v2 "> l2 </option>
</select>
<input type= "hidden " name= "hide1 ">
<input type= "submit " onclick= "document.all[ 'hide1 '].value=document.all[ 'select1 '].options[document.all[ 'select1 '].selectedIndex].text; ">
</form>
</body>
------解决方案--------------------
我觉的可以变通一下 改为
jsp页面中:
<html:select property= "interesting " multiple= "true ">
<html:option value= "htmlselect.sing$Sing "> Sing </html:option>
<html:option value= "htmlselect.print$Print "> Print </html:option>
<html:option value= "htmlselect.film$Film "> Film </html:option>
<html:option value= "htmlselect.computerGame$Computer Game "> Computer Game </h