表内删除的行我有以下看法: -如何删除使用jQuery我的asp.net MVC
<script type="text/javascript">
$(document).ready(function() {
$("#removerow").click(function() {
$(this).remove();
});
});
</script>
<h2>Details</h2>
<fieldset>
<legend>This Question Currently has @Model.Answers.Count() Answers/s. </legend>
<table id="incrementanswer">
<tr>
<th>
Description
</th>
<th>
Answer
</th>
<th></th>
</tr>
@foreach (var answer in Model.Answers.OrderBy(a=> a.IsRight))
{
<tr id = "removerow">
<td>
@Html.DisplayFor(modelItem => answer.Description)
</td>
<td>
@Html.DisplayFor(modelItem => answer.Answer_Description.description)
</td>
<td>
@Ajax.ActionLink("Delete", "Delete", "Answer",
new { id = answer.AnswersID },
new AjaxOptions
{
Confirm = "Are You sure You want to delete this Answer ?",
HttpMethod = "Post",
UpdateTargetId = "toremove",
OnSuccess = "removePartial2"
})
</td>
</tr>
}
</table>
<div id = "progress2">
<img src= "@Url.Content("~/Content/images/ajax-loader1.gif") ">
</div>
其中包含脚本和ajax.actionlink在点击后调用此脚本在删除链接上。目前,只有当它是表中的第一行时,该行才会被删除,并且在确认删除之前该行将被删除,那么可能是什么问题?
编辑: - 我我的观点已经更新到了下面,但我仍然不能强迫removePartial2脚本删除其删除的行: - 。
</script>
<script type="text/javascript">
function removePartial2() {
$(this).remove();
}
</script>
}
<h2>Details</h2>
<fieldset>
<legend>This Question Currently has @Model.Answers.Count() Answers/s. </legend>
<table id="incrementanswer">
<tr>
<th>
Description
</th>
<th>
Answer
</th>
<th></th>
</tr>
@foreach (var answer in Model.Answers.OrderBy(a=> a.IsRight))
{
<tr id = @answer.AnswersID>
<td>
@Html.DisplayFor(modelItem => answer.Description)
</td>
<td>
@Html.DisplayFor(modelItem => answer.Answer_Description.description)
</td>
<td>
@Ajax.ActionLink("Delete", "Delete", "Answer",
new { id = answer.AnswersID },
new AjaxOptions
{
Confirm = "Are You sure You want to delete this Answer ?",
HttpMethod = "Post",
UpdateTargetId = @answer.AnswersID.ToString(),
OnSuccess = "removePartial2"
})
</td>
</tr>
}
</table>
<div id = "progress2">
<img src= "@Url.Content("~/Content/images/ajax-loader1.gif") ">
</div>
ID。必须。是。独特。 – 2012-03-07 15:11:13
什么是您的removePartial2中的$(this)?你确定它引用了你想要的对象吗? – Rastapopulous 2012-03-07 22:05:33
我想强制应用程序删除预期的行,那为什么我使用$(this);但似乎它不工作...... – 2012-03-07 22:51:59