我已将此程序编写为从数据库中获取下拉多选择器数据,并显示多选择器的所有选项,并突出显示所选选项和剩余选项。
<% String[] skills=(String[])request.getAttribute("skills");
//skills[]={"Core Java","Hibernate","Sql}; // it is dynamic d
String[] allSkills={"Core Java","J2ee","Spring","Hibernate","Sql",".net"};
%>
<tr>
<td>Skills Known</td>
<td><select name="skills" multiple STYLE="width: 148px">
<% for(int i=0;i<allSkills.length-1;i++){
for (int j=0;j<skills.length-1;j++){
if(allSkills[i].equals(skills[j])){%>
<option value=<%=allSkills[i] %> selected="selected"><%=allSkills[i] %></option>
<%return; %>
<%}else if(j==skills.length-1){%>
<option value=<%=allSkills[i] %>><%=allSkills[i] %></option>
<%}
}
}%>
</select>
</td>
</tr>
答案 0 :(得分:0)
<%
/ *从数据库* /
获取数组技能String[] skills = (String[]) request.getAttribute("skills");
/ *在drop do * /
中写下所有选项availbaleString[] allSkills = { "Core Java", "J2ee", "Spring", "Hibernate", "Sql", ".net"
>%
/ *多选择器的代码为* /
<tr>
<td>Skills Known</td>
<td><select name="skills" multiple STYLE="width: 148px">
<%
for (int counter = 0; counter < allSkills.length; counter++) {
int status = 0;
for (String str : skills) {
if (!(str.equalsIgnoreCase(allSkills[counter]))) {
continue;
} else {
status++;
}
}
if (status > 0) {
%>
<option value="<%=allSkills[counter]%>" selected="selected"><%=allSkills[counter]%></option>
<%
} else {
%>
<option value="<%=allSkills[counter]%>"><%=allSkills[counter]%></option>
<%
}
}
%>
</select></td>
</tr>