<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="JS/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#divClike").click(function () {
/*appendTo意为将前面查询到的DOM节点插入后面查询到的节点中,
$("#ddlSelect").appendTo($("#divSelect"));这句话的意思就是将前面查询到的ID为ddlSelect的节点,剪切插入到ID为divSelect的DOM节点中间,
正因为是剪切,才用clone()函数对前面节点进行复制
*/
$("#ddlSelect").clone().appendTo($("#divSelect"));
});
$("#divshowClike").click(function () {
var a = "";
$(".Select1").each(function () {
a = a + $(this).val();
});
$("#lblShow").text(a);
$("#hid").val(a);
});
$("#lblShow").click(function () {
$("#lblShow").text();
$("#hid").val();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divClike">增加下拉列表框</div>
<div id="divSelect">
<asp:DropDownList ID="ddlSelect" CssClass="Select1" runat="server">
<asp:ListItem Value="a">1</asp:ListItem>
<asp:ListItem Value="B">2</asp:ListItem>
<asp:ListItem Value="C">3</asp:ListItem>
</asp:DropDownList>
</div>
<div id="divshowClike">显示值</div>
<input type="hidden" id="hid" runat="server" />
<asp:Label ID="lblShow" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(Button1, this.GetType(), "but", "alert('" + hid.Value + "');", true);
}