针对select写了一个通用的option输出函数

function writeSlt(arrstr,arrstrValue,selectedstr)
'arrstr 要显示在option里面的值,arrstrValue option的实际值,selectedstr要选中的默认值
'将一个字串分割为数组,输出select的option,并选中selectedstr arrstr&arrstrValue长度要一致
arr=split(arrstr,",")
arrValue=split(arrstrValue,",")
j=0
do while j<=ubound(arr)
if trim(arrValue(j))=trim(selectedstr) then
response.write "

1<option selected="" value='" &amp; arrValue(j) &amp; "'>" &amp; arr(j) &amp; "</option>

"
else
response.write "

1<option value='" &amp; arrValue(j) &amp; "'>" &amp; arr(j) &amp; "</option>

"
end if
j=j+1
loop
end function

可以从数据库中读出数据,形成逗开分隔的字符串,来动态生成select的

 1<option>
 2
 3function getArrString(table,fld,cond,sortfld)   
 4'获取一个指定表中指定字段指字条件的数据,返回一个以逗号分隔的字符串   
 5set rs=server.createobject("adodb.recordset")   
 6sql="select " &amp; fld &amp; " from " &amp; table   
 7if len(cond)&gt;0 then   
 8sql=sql &amp; " where " &amp; cond   
 9end if   
10if len(sortfld)&gt;0 then   
11sql=sql &amp; " order by " &amp; sortfld   
12end if   
13rs.Open sql,conn,1,1   
14if not (rs.bof or rs.EOF) then   
15do while not rs.EOF   
16getArrString=getArrString &amp; trim(rs(fld)) &amp; ","   
17rs.MoveNext   
18loop   
19end if   
20getArrString=left(getArrString,len(getArrString)-1)   
21rs.Close   
22set rs=nothing   
23end function</option>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus