我能够在后面的代码中放置一个具有自定义ID的div
,我需要知道如何删除或向自定义div
添加更多内容...
我尝试过locate.InnerHTML
,但是当然没有用。
还有ClientScript.RegisterStartupScript(this.GetType(),"remove","<script>$('" + locate + "').remove();</script>");
,什么都没发生。
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Test2.aspx.cs" Inherits="StepFollowingDemo.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<br />
<asp:button runat="server" type="button" ID="BtnAdd" Text="Add more" class="btn btn-basic"/>
<asp:button runat="server" type="button" ID="BtnAdd2" Text="Add Dual" class="btn btn-warning"/> <!--This button is meant to delete the last <div> placed by the id ignore the name for now-->
<hr />
<div runat="server" class="well container">
<div id="TestDiv" runat="server" class="row">
</div>
</div>
<br />
<div class="well">
<div class="row">
<div class="well col-sm-1">1.</div>
</div>
<div class="row">
<div class="well col-sm-1">a1.</div>
<div class="well col-sm-1">b1.</div>
</div>
</div>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using system.web;
using system.web.UI;
using system.web.UI.WebControls;
namespace StepFollowingDemo
{
public partial class WebForm1 : system.web.UI.Page
{
static int counter = 1;
string count = counter.ToString(); //Step count
string locate = "add"+(counter - 1).ToString(); //Locate last step by id
public void Page_Load(object sender,EventArgs e)
{
BtnAdd.Click += BtnAdd_Click; //Add singular step
BtnAdd2.Click += BtnAdd2_Click; //Add a two way step
}
private void BtnAdd2_Click(object sender,EventArgs e)
{
//Response.Write("<script>alert('"+locate+"')</script>"); //Alert to know wich one is the latest step
//ClientScript.RegisterStartupScript(this.GetType(),"<script>$('" + locate + "').remove();</script>");
}
private void BtnAdd_Click(object sender,EventArgs e)
{
counter++;
TestDiv.InnerHtml += "<div id='add"+ count +"'runat='server' class='col-sm-4'>";
TestDiv.InnerHtml += "<h3>"+count+". </h3>";
TestDiv.InnerHtml += "<p>Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum.</p>";
TestDiv.InnerHtml += "</div>";
}
}
}
此按钮需要删除通过捕获生成的自定义ID放置的项目,如果你们还有我可以做的其他事情,将不胜感激!