是这样的,我先出一个文本框和一个添加按钮,然后点击添加按钮就加一个文本框,可是怎么搞也只能出一个,点击事件只有一次有效,也就是说只能添加一个,怎么办?页面代码: <input id="Text1" type="text" runat="server" value="01" />
<asp:PlaceHolder ID="phlYjfx" runat="server"></asp:PlaceHolder>
<asp:Button ID="btnAdd" runat="server" OnClick="Add_Click" Text="继续添加" BackColor="#404040" />
后台代码public partial class admin_ZyAdd : System.Web.UI.Page
{
int i = 1;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Add_Click(object sender, EventArgs e)
{
i++;
TextBox txtYjfx = new TextBox();
txtYjfx.ID = "txt" + i;
phlYjfx.Controls.Add(txtYjfx);
} }
}
<asp:PlaceHolder ID="phlYjfx" runat="server"></asp:PlaceHolder>
<asp:Button ID="btnAdd" runat="server" OnClick="Add_Click" Text="继续添加" BackColor="#404040" />
后台代码public partial class admin_ZyAdd : System.Web.UI.Page
{
int i = 1;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Add_Click(object sender, EventArgs e)
{
i++;
TextBox txtYjfx = new TextBox();
txtYjfx.ID = "txt" + i;
phlYjfx.Controls.Add(txtYjfx);
} }
}
function cloneIt(which){
oSpan = which.parentNode
oParent = oSpan.parentNode
oChidren= oParent.children
if( which.value != "" ){
if( oSpan == oChidren[oChidren.length-1]){
var cloneWhich = oSpan.cloneNode(true)
cloneWhich.children[0].value = ''
oSpan.parentNode.appendChild(cloneWhich)
cloneWhich.children[0].focus()
}
}else if( oSpan == oChidren[oChidren.length-1] ){
return
}else{
which.parentNode.outerHTML = ''
}
} <td height="40" colspan="3" id="draw_Variety">
<span><input name="cApply_Variety" type="text" class="input1px_date" style="width:100" onblur="cloneIt(this)"> </span>
</td>