我想在代码中多次将现有div(var parent)附加到新div。这是我的代码。它将现有div附加到最后创建的div。帮助我。
@model AllExamples.DTO.EmployeeInfo
@{
ViewBag.Title = "Home Page";
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@*@Html.AntiForgeryToken()*@
@Html.ValidationSummary(false)
<div class="form-group">
@Html.Label("Employee Name", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.EmployeeName, new { @class = "form-control", Name = "EmployeeName" })
@Html.ValidationMessageFor(m => m.EmployeeName)
</div>
</div>
<div class="form-group">
@Html.Label("Email ID", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.EmailID, new { @class = "form-control",Name= "EmailID" })
@Html.ValidationMessageFor(m => m.EmailID)
</div>
</div>
<div class="form-group">
@Html.Label("Contact Number", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.ContactNumber, new { @class = "form-control", Name = "ContactNumber" })
@Html.ValidationMessageFor(m => m.ContactNumber)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Save" />
</div>
</div>
}
答案 0 :(得分:0)
看起来你在那里的第8行翻了你的孩子和父母。我想你想说parent.appendChild(newDiv);
答案 1 :(得分:0)
一个元素不能存在于多个位置,因此如果要重用元素的标记,则可以使用cloneNode来克隆它。
document.getElementById("feed").appendChild(newdiv.cloneNode(true));