我做了一个下拉框筛选的功能,可是功能老是不能实现,不管选择哪一个选项,都只显示第一项,下面是代码,我总觉得逻辑是对的,不知道语法上有没有错,asp中可以实现.请教高手,谢谢先.
while(rs3.next())
{
%>
<option value="<%= rs3.getString("id") %>" <% if(rs3.getString("id")==request.getParameter("cid")) out.println("selected"); %>><%= rs3.getString("name") %></option>
<%
}
while(rs3.next())
{
%>
<option value="<%= rs3.getString("id") %>" <% if(rs3.getString("id")==request.getParameter("cid")) out.println("selected"); %>><%= rs3.getString("name") %></option>
<%
}
<option value="——" selected>请选择</option>
<%
while(rs3.next())
{
%>
<option value="<%rs3.getString("id")%>"><%=rs3.getString("id")%></option>
<%
}
%>
</select>
if(rs3.getString("id").equals(request.getParameter("cid")))
==是数字的比较,equals是字符串比较
你也可以看下你的页面的源代码!
如果还不行的话,建议使用javascript.这个通用!
<head>
<script language="javascript">
function setOptionChecked() {
var select1 = document.getElementById("select1");
var opValue = select1.value;
var op = document.getElementById("select1").options;
for (var i=0;i<op.length;i++) {
if (opValue == op[i].value) {
op[i].selected;
}
}
}
</script>
</head>
<body>
<select name="select1" id="select1" onchange="setOptionChecked()">
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
</select>
</body>
</html>
(rs3.getString("id")==request.getParameter("cid"))
这里不能用等于号,把他改为:rs3.getString("id").equalsIgnoreCase(request.getParameter("cid")) ;
试下
while(rs3.next())
{
%>
<option value=" <%= rs3.getString("id") %> " <% if("request.getParameter("cid")".equals(rs3.getString("id"))out.println("selected"); %> > <%= rs3.getString("name") %> </option>
<%
}
试试
<option value="" <%if(null==equipType||"".equals(equipType)) out.print("selected");%>>-所有类型-</option>
<%
strSql="...";
rs = stmt.executeQuery(strSql);
while(rs.next()) {
String typeId = rs.getString("."));
String typeName =rs.getString(".."));
%>
<option value="<%=typeId%>" <%if(typeId.equals(equipType)) out.print("selected");%>><%=typeName%></option>
试试这样哦 equipType在页面前面接受