为for循环中的项提供Id
本文关键字:Id for 循环 | 更新日期: 2023-09-27 17:58:19
伙计们,我正在生成一系列文本框,旁边有一个按钮(在li标签中)作为
<div class="col-md-10">
<ul id="sortable" style="list-style-type: none; padding-left: 0;">
@for (int i = 0; i < Model.BulletPoints.Count(); i++)
{
<li class="ui-state-default" style="margin-bottom: 8px;"><span>@Html.TextBoxFor(m => m.BulletPoints[i], new { @maxlength = "200", @class = "form-control", @style = "width: 825px;max-width: 90%;" }) <div style="width: 70px; max-width: 10%; margin-top: -30px; float: right;"><span class="ui-icon ui-icon-arrowthick-2-n-s" style="margin-top: 4px; float: left;"></span> <input type="button" style="float: right;" value="X" onclick="SubmitForm('deletebullet')" /></div></span></li>
}
</ul>
</div>
注意BulletPoints在模型中为public List<string> BulletPoints { get; set; }
。
然而,现在我必须通过点击旁边的按钮来删除这些文本框中的任何一个
如何实现这一点有什么帮助吗?
<ul>
@for (int i = 0; i < Model.BulletPoints.Count(); i++)
{
<li class="ui-state-default" style="margin-bottom: 8px;"><span>@Html.TextBoxFor(m => m.BulletPoints[i], new { @maxlength = "200", @class = "form-control", @style = "width: 825px;max-width: 90%;" }) <div style="width: 70px; max-width: 10%; margin-top: -30px; float: right;"><span class="ui-icon ui-icon-arrowthick-2-n-s" style="margin-top: 4px; float: left;"></span> <input type="button" style="float: right;" value="X" onclick="SubmitForm(this)" /></div></span></li>
}
</ul>
<script>
function SubmitForm(obj) {
$(obj).parent().siblings().remove();
}
</script>