我用的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和显示文本写成一样的。
高手指点一下,分不多了,多谢。
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: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 表示出来
-------------
有点糊涂
form里面定义2个list, 分别用来表示codeList和nameList,
再定义个String 来表示所选择的值selectItem然后在java程序里。
codeList.add("1");
codeList.add("2");
codeList.add("3");
codeList.add("4");
codeList.add("5");nameList.add("Sing")
nameList.add("Print")
...
...selectItem = “随便一个初始值”然后就OK了
arrayList.add(new LabelValueBean("1002","name2"));
arrayList.add(new LabelValueBean("1003","name3"));request.setAttribute("list",arrayList);------------------
在JSP页面如下
<html:select property="username">
<html:options collection="list" property="id" labelProperty="name" />
</html:select/>这样可以实现,不过我是直接转到jsp页面,这句request.setAttribute("list",arrayList);
我应当放哪合适。不能放到JSP中
--------------
感觉有问题啊,我是想要得到显示的值,并不是如何显示的问题啊。呵呵
<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</html:option>
<html:option value="htmlselect.other$Other">Other</html:option>
</html:select>
然后根据传进的值是否indexOf(数组[i]) != -1 ,那么split('$')后的数组[1]就是得到的值了
我对js不熟悉,现在把select用options了,全部放到一个properties里面,value和text设定成一样的,不搞那末复杂了。也看不出什莫优势阿。
value和text不一样真的有优势吗
arrayList.add(new LabelValueBean("1002","name2"));
arrayList.add(new LabelValueBean("1003","name3"));request.setAttribute("list",arrayList);
可以在Action里实现.
<html:select property="username">
<html:options collection="list" property="id" labelProperty="name" />
</html:select/>
_____________________________________
正解