0

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

我有以下脚本

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
4

2 回答 2

0

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

于 2013-06-13T05:30:04.653 回答
0

尝试

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>"
于 2013-06-13T07:07:33.067 回答