ASP Classic- split()按多值选择的值

时间:2017-05-25 03:42:19

标签: split asp-classic

我有多个选择如下:

<select name="fnme" onchange="myFnm()" multiple>
  <option value="STR12(12,YU,IO)">STR12(12,YU,IO)</option>
  <option value="STR13(13,YU,IO)">STR12(13,YU,IO)</option>
  <option value="STR14(14,YU,IO)">STR12(14,YU,IO)</option>
  <option value="STR15(15,YU,IO)">STR12(15,YU,IO)</option>
</select>

ASP代码:

<%
dim fnm,element
fnm=Split(Request("fnme"),",")
for each element in fnm
  Response.Write("<p>--qq-- " & element & " </p>")
Next
%>

当我选择&#34; STR12(12,YU,IO)&#34;和&#34; STR12(13,YU,IO)&#34; ,输出将变成这样:

--qq-- STR12(12 

--qq-- YU

--qq-- IO)

--qq-- STR13(13 

--qq-- YU

--qq-- IO)

而不是这种输出我希望输出如下:

--qq-- STR12(12,YU,IO)

--qq-- STR12(13,YU,IO)

1 个答案:

答案 0 :(得分:0)

我会在每个值的末尾添加一个分隔符,如下所示:

<select name="fnme" onchange="myFnm()" multiple>
  <option value="STR12(12,YU,IO)|">STR12(12,YU,IO)</option>
  <option value="STR13(13,YU,IO)|">STR12(13,YU,IO)</option>
  <option value="STR14(14,YU,IO)|">STR12(14,YU,IO)</option>
  <option value="STR15(15,YU,IO)|">STR12(15,YU,IO)</option>
</select>

然后,您的ASP代码将是:

<%
dim fnm,element
fnm=Split(fnme,"|,")
for each element in fnm
   if element <> "" then
      if Right( element, 1 ) = "|" then element = Left( element, Len( element ) - 1 )
      Response.Write("<p>--qq-- " & element & " </p>")
   end if
Next
%>