ASP通用条件查询模块的源代码:
<Script LANGUAGE=javaScript>
<!--
//隐藏或显示条件查询模块
function search_dis(ob){
if (ob.style.display=="none")
{ob.style.display="";window.location.href (#down);}
else
{ob.style.display="none";}
}
//把条件查询语句添加到<select>查询列表框;
function AddSe(){
var val,val_tmp,Sql,oAdd,TextType;
var Field,Condition,TextVal,Relation;
Field=frm_Search.Field.options[frm_Search.Field.selectedIndex].text;
TextVal=""+frm_Search.TextVal.value+"" ;
Condition=frm_Search.Condition.options[frm_Search.Condition.selectedIndex].text;
Relation=frm_Search.Relation.options[frm_Search.Relation.selectedIndex].text;
val_tmp = frm_Search.Field.value;
val_tmp = val_tmp.substring(0,1);
//判断字段的数据类型,如果为1,就是字符、日期型;为2,就是数值型;
if (val_tmp==1)
{TextType=""+frm_Search.TextVal.value+" " ;}
else
{TextType=""+frm_Search.TextVal.value+" " ;}
val_Field = frm_Search.Field.value;
val_Field = val_Field.substr(1);
val= val_Field + frm_Search.Condition.value + TextType + frm_Search.Relation.value ;
Sql = Field+Condition+TextVal+Relation;
oAdd=document.createElement("option")
oAdd.value=val;
oAdd.text=Sql;
frm_Search.seSql.add(oAdd);
}
//把条件查询语句从<select>查询列表框中删除;
function moveSe(){
for (i=1;i<frm_Search.seSql.options.length;i++){
if(frm_Search.seSql.options[i].selected){
frm_Search.seSql.remove(frm_Search.seSql.selectedIndex);
}
}
}
//取得查询条件,并提交;
function getVal(){
var gettxt,Setable;
gettxt = "";
var path = window.location.pathname ; //取得页面链接和文件名
var line = path.lastIndexOf("/"); //取得最后一个/的位置
var dot = path.indexOf("."); //取得第一个.的位置
var Name = path.substring(line+1,dot); //取得文件名
var fileName = Name + ".asp";
for (i=1;i<frm_Search.seSql.options.length;i++){
gettxt = gettxt+ " " + frm_Search.seSql.options[i].value ;}
var valLeng=gettxt.lastIndexOf(" ");
gettxt=gettxt.substr(0,valLeng); //去掉条件子句的最后一个关系运算符
Setable = frm_Search.Setable.value ;
//window.open (fileName+?gettxt=+gettxt,_self); //向当前页面传送查询条件子句
frm_Search.getSql.value = gettxt;
frm_Search.action = fileName;
frm_Search.submit ();
}
//-->
</Script>
<table width="100%" border="0" cellspacing="0" cellpadding="0"><Form Name="frm_Search" method="post" action="">
<input type="hidden" Name=getSql Value="">
<tr>
<td width="25%" bgcolor="#006699"><font color="#FFFFFF" style="font-size:10pt">查询条件:</font></td>
<td width="25%" bgcolor="#F2F2F2"> <select Name="Condition" style="font-size:12px">
<option Value="=">等 于</option>
<option Value=">">大 于</option>
<option Value=">=">大于等于</option>
<option Value="<">小 于</option>
<option Value="<=">小于等于</option>
<option Value="<>">不等于</option>
<option Value=" NULL ">为空</option>
<option Value=" NOT NULL ">不为空</option>
<option Value=" LIKE ">匹配</option>
</select></td>
<td width="25%" bgcolor="#F2F2F2"> <input type="button" Name="AddSql" Value="添加>>>" onClick="AddSe()" ></td>
<td width="25%" rowspan="4" bgcolor="#F2F2F2"> <select id="seSql" size="6">
<option Value="">------------查询条件-----------</option>
</select></td>
</tr>
<tr>
<td bgcolor="#006699"><font color="#FFFFFF" style="font-size:10pt"> 查询字段:</font></td>
<td bgcolor="#F2F2F2"> <select Name="Field" style="font-size:12px"><%Call SearchField()%></select></td>
<td bgcolor="#F2F2F2"> <input type="button" Name="delSql" Value="<<<删除" onClick="moveSe()" ></td>
</tr>
<tr>
<td bgcolor="#006699"><font color="#FFFFFF" style="font-size:10pt">条 件 值:</font></td>
<td bgcolor="#F2F2F2"> <input type="text" id="TextVal" size="15"></td>
<td bgcolor="#F2F2F2"> </td>
</tr>
<tr>
<td bgcolor="#006699"><font color="#FFFFFF" style="font-size:10pt">关系运算符:</font></td>
<td bgcolor="#F2F2F2"> <select Name="Relation" style="font-size:12px">
<option Value="and">并且</option>
<option Value="or">或者</option>
</select></td>
<td bgcolor="#F2F2F2"> <input type="button" Name="search_ok" Value="查 询" onClick="getVal()" ></td>
</tr></Form>
</table>
<%Sub SearchField()
Response.Write "<option Value=1Title>标题</option>"
Response.Write "<option Value=1Time>时间</option>"
Response.Write "<option Value=1Content>内容</option>"
Response.Write "<option Value=1User>发布人</option>"
End Sub%>