function writeSlt(arrstr,arrstrValue,selectedstr) 'arrstr 要顯示在option里面的值,arrstrValue option的實(shí)際值,selectedstr要選中的默認(rèn)值 '將一個(gè)字串分割為數(shù)組,輸出select的option,并選中selectedstr arrstr&arrstrValue長(zhǎng)度要一致 arr=split(arrstr,",") arrValue=split(arrstrValue,",") j=0 do while j<=ubound(arr) if trim(arrValue(j))=trim(selectedstr) then response.write "<option value='" & arrValue(j) & "' selected>" & arr(j) & "</option>" else response.write "<option value='" & arrValue(j) & "'>" & arr(j) & "</option>" end if j=j+1 loop end function 可以從數(shù)據(jù)庫(kù)中讀出數(shù)據(jù),形成逗開(kāi)分隔的字符串,來(lái)動(dòng)態(tài)生成select的<option> function getArrString(table,fld,cond,sortfld) '獲取一個(gè)指定表中指定字段指字條件的數(shù)據(jù),返回一個(gè)以逗號(hào)分隔的字符串 set rs=server.createobject("adodb.recordset") sql="select " & fld & " from " & table if len(cond)>0 then sql=sql & " where " & cond end if if len(sortfld)>0 then sql=sql & " order by " & sortfld end if rs.Open sql,conn,1,1 if not (rs.bof or rs.EOF) then do while not rs.EOF getArrString=getArrString & trim(rs(fld)) & "," rs.MoveNext loop end if getArrString=left(getArrString,len(getArrString)-1) rs.Close set rs=nothing end function
|