繁体   English   中英

经典ASP-选择下拉列表中的IF语句

[英]Classic ASP - IF statement in a select drodown

我想知道是否有人可以帮我解决问题。

我有以下脚本

strInput = "<select name=""winner"">" &_
    "<option></option>" &_
    "<option value=""1"">1st</option>" &_
    "<option value=""2"">2nd</option>" &_
    "<option value=""3"">3rd</option>" &_
    "<option value=""4"">4th</option>" &_
"</select>"

如何在选项中插入“ if”语句以检查值,然后默认选择该选项

if intVal = 1 then
    selected="selected"
End If

"<option value=""1"" " & iif(intVal = 1, " ""Selected"" ", " ") & ">1st</option>"

尝试

strInput = "<select name=""winner"">"
strInput = strInput &  "<option></option>"
strInput = strInput &  "<option value=""1"""
If intVal = 1 Then
    strInput = strInput &  " selected"
End If
strInput = strInput &  ">1st</option>"
strInput = strInput &  "<option value=""2"""
If intVal = 2 Then
    strInput = strInput &  " selected"
End If
strInput = strInput &  ">2st</option>"
strInput = strInput &  "<option value=""3"""
If intVal = 3 Then
    strInput = strInput &  " selected"
End If
strInput = strInput &  ">3st</option>"
strInput = strInput &  "<option value=""4"""
If intVal = 4 Then
    strInput = strInput &  " selected"
End If
strInput = strInput &  ">4st</option>"
strInput = strInput &  "</select>"

要么

Function IsSelected(optionValue, defaultValue)
    If optionValue = defaultValue Then
        IsSelected = " selected"
    Else
        IsSelected = ""
    End If
End Function

strInput = "<select name=""winner"">" &_
    "<option></option>" &_
    "<option value=""1""" & IsSelected(1,intVal) & ">1st</option>" &_
    "<option value=""2""" & IsSelected(2,intVal) & ">2nd</option>" &_
    "<option value=""3""" & IsSelected(3,intVal) & ">3rd</option>" &_
    "<option value=""4""" & IsSelected(4,intVal) & ">4th</option>" &_
"</select>"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM