关于JS动态生成input,后台获取值的问题
<script type="text/javascript">
function Creat() {
var textBoxId = document.createElement("input");
textBoxId.nodeType = "text";
textBoxId.nodeName = "textBoxId1";
document.getElementById("GoodsBox").appendChild(textBoxId);
}
</script>
<div>
<form action="Default2.aspx" method="post" id="GoodsBox">
<input type="submit" value="提交" />
</form>
<input type="button" onclick="Creat()" value="创建" />
</div>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function Creat() {
var textBoxId = document.createElement("input");
textBoxId.setAttribute("type", "text");
textBoxId.setAttribute("id", "textBoxId1");
document.getElementById("GoodsBox").appendChild(textBoxId);
}
function Test() {
document.getElementById("Hidden1").value = document.getElementById("textBoxId1").value;
document.getElementById("<%=HiddenField1.ClientID%>").value = document.getElementById("textBoxId1").value;
}
</script>
</head>
<body>
<div>
<form runat="server" id="GoodsBox">
<input type="submit" value="提交" />
<input type="button" onclick="Creat()" value="测试创建" />
<input type="button" onclick="Test()" value="测试获取值" />
<input id="Hidden1" name="Hidden1" type="hidden" value="" />
<asp:HiddenField ID="HiddenField1" runat="server" Value="" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
</div>
</body>
</html>
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script> alert('" + HiddenField1.Value + "') </script>");
}