<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function Create()
{
var ddl=document.getElementById('<%=ddlSearch.ClientID %>');
var index=ddl.selectedIndex;//取得当前的选中值
var Value=ddl.options[index].value;
var Text=ddl.options[index].text;
var at = document.createElement('INPUT');
at.setAttribute('type' , 'text');
at.setAttribute('name','txt1');
at.setAttribute('value','ok');
var txtNode = document.createTextNode(Text+'=');
var back = document.createElement("span");
back.innerHTML="<br />";
document.getElementById("panc").appendChild(txtNode);
document.getElementById("panc").appendChild(at);
document.getElementById("panc").appendChild(back);
var hd=document.getElementById('hd');
if(hd.value=="")
{
hd.value+=Value;
}else
{
hd.value+="|"+Value;
}
}
</script>
<style type="text/css">
#panc input
{
width:40px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center;">
查询条件:
<asp:DropDownList runat="server" ID="ddlSearch" >
<asp:ListItem Text="性别" Value="sex"></asp:ListItem>
<asp:ListItem Text="银行" Value="bank"></asp:ListItem>
<asp:ListItem Text="姓名" Value="name"></asp:ListItem>
</asp:DropDownList>
<br /> <br />
<input type="hidden" id="hd" name="hd" />
<div id="panc" style="text-align:center;">
</div>
<input type="button" value="添加查询条件" οnclick="Create();" /><br />
<asp:Label runat="server" ID="lblMessage" Text="" ForeColor="Red"></asp:Label><br />
<asp:Button runat="server" ID="btnGo" Text="提交" οnclick="btnGo_Click" />
</div>
</form>
</body>
</html>
后台取值:
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Text = "";
}
protected void btnGo_Click(object sender, EventArgs e)
{
string v = Request.Form["hd"].ToString();
string t = Request.Form["txt1"].ToString();
string[] vv = v.Split('|');
string[] tt = t.Split(',');
if (null != vv && null != tt && vv.Length == tt.Length)
{
for (int i = 0; i < vv.Length; i++)
{
lblMessage.Text += vv[i] + "=" + tt[i] + ";";
}
}
}