Bmw*_*Bmw 3 postback asp-classic
我正在使用经典的asp,我有一个用户选择的下拉列表,然后按下提交.按下提交后,下拉列表将返回默认值而不是他们选择的值.反正是否保持帖子后退之间的下拉状态而不是恢复到默认状态?如果需要,可以发布代码示例.谢谢!
Est*_*ber 11
您必须根据用户已发布的值"选择"服务器端.
<select id="cars">
<option value="volvo"
<%
if request.form("cars") = "volvo" then
response.write("selected")
end if %>
>Volvo</option>
<option value="Saab"
<%
if request.form("cars") = "Saab" then
response.write("selected")
end if %>
>Saab</option>
<option value="Mercedes"
<%
if request.form("cars") = "Mercedes" then
response.write("selected")
end if %>
>Mercedes</option>
<option value="Audi" <%
if request.form("cars") = "Audi" then
response.write("selected")
end if %>
>Audi</option>
</select>
Run Code Online (Sandbox Code Playgroud)
当然,你可能想要自己开发自己的函数来避免所有的样板.
<%
sub option(value, data, select_id)
Response.Write("<option value=""" & value & """)
if request.form(select_id) = value then
Response.Write("selected")
end if
Response.Write(">" & data & "</option>")
end sub
%>
' (...)
<select id="cars">
<% option("volvo", "Volvo", "cars") %>
<% option("Saab", "Saab", "cars") %>
<% option("Mercedes", "Mercedes", "cars") %>
<% option("Audi", "Audi", "cars") %>
</select>
Run Code Online (Sandbox Code Playgroud)
如果您将该函数传递给空白select_id,则无需尝试选择select回发时所选项目.