下面是我的ASP经典code.i有问题,如果把if if语句那样......实际上它不工作..我想做的是当我选择美国然后提交它将显示选择USA..default是ALL.sorry我的英语不好。
<% Response.write"<form action=""untitled.asp"" method=""post"">"
Response.write"<select name=""country"">"
Response.write"<option selected>ALL</option>"
Response.write" <option value=""1"" if request(""country"")=""1"" then
Response.Write""selected"">USA</option>"
Response.write" <option value=""2"" if request(""country"")=""2"" then
Response.Write""selected"">BRAZIL</option>"
Response.write"<label>"
Response.write" <input type=submit name=button id=button value=Submit />"
Response.write"</label>"
Response.write"</form>"
%>
感谢
答案 0 :(得分:1)
您的基本语法错误。这是应该如何做的:
Response.write " <option value=""1"""
If request("country")="1" then
Response.Write " selected=""selected"""
End If
Response.Write ">USA</option>"
第二种选择也一样。为了使其更灵活和可读,请使用以下函数:
Function BuildOption(sValue, sRequestKey, sText)
Dim sHTML
sHTML = "<option value=""" & sValue & """"
If Request(sRequestKey)=sValue Then
sHTML = sHTML & " selected=""selected"""
End If
sHTML = sHTML & ">" & sText & "</option>"
BuildOption = sHTML
End Function
然后像这样使用它:
Response.write BuildOption("1", "country", "USA")
Response.write BuildOption("2", "country", "BRAZIL")