62,272
社区成员
发帖
与我相关
我的任务
分享<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dynamicAdd.aspx.cs" Inherits="WebApp.dynamicAdd" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function addFile() {
var div = document.createElement("div");
var f = document.createElement("input");
f.setAttribute("type", "text")
f.setAttribute("name", "txtCardNo")
f.setAttribute("size", "20")
div.appendChild(f)
var d = document.createElement("input");
d.setAttribute("type", "button")
d.setAttribute("onclick", "deteFile(this)");
d.setAttribute("value", "移除")
div.appendChild(d)
document.getElementById("_container").appendChild(div);
}
function deteFile(o) {
while (o.tagName != "DIV") o = o.parentNode;
o.parentNode.removeChild(o);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input value="add" type="button" onclick="addFile()" />
<div id="_container">
</div>
<input type="submit" value="ok" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApp {
public partial class dynamicAdd : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
if (string.IsNullOrEmpty(Request["txtCardNo"])) {
string[] strCardes = Request["txtCardNo"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string strCard in strCardes) {
//to do
}
}
}
}
}
}