[英]Update input tag value on anchor tag click
I've a div 我有一个div
@{int index = 0;}
@for (int i = 0; i < Model.lstFiles.Count; i++)
{
<div id="attachmentDetail(@index)" name="attachmentDetail(@index)" class="panel-body">
<a asp-action="Download" asp-controller="Admin" asp-route-realName=Model.lstFiles[i].RealName>@Model.lstFiles[i].FileName</a>
<a onclick="btnDelFile_Click(@index)" id="btnDelFile{@index}" class="pull-right" title="delete"><img height="20" width="20" src="@Url.Content("~/images/delete.jpg")" /></a>
<input type="text" asp-for="@Model.lstFiles[i].IsDeleted" hidden />
<input type="text" asp-for="@Model.lstFiles[i].FileId" hidden />
<hr />
</div>
index++;
}
I want to update @Model.lstFiles[i].IsDeleted
value on btnDelFile_Click
. 我想更新
@Model.lstFiles[i].IsDeleted
价值btnDelFile_Click
。 But I'm unable to get div and its child. 但是我无法得到div及其孩子。 I tried this code
我尝试了这段代码
$('#attachmentDetail(' + index +') :input lstFiles['+index+'].IsDeleted').val("True");
but it says 但它说
jquery.min.js:2 Uncaught Error: Syntax error, unrecognized expression: #attachmentDetail(0)
jquery.min.js:2未捕获的错误:语法错误,无法识别的表达式:#attachmentDetail(0)
Is there any better way to get child of div?? 有没有更好的办法让div的孩子? I want to update
IsDeleted
value, and then hide this div. 我想更新
IsDeleted
值,然后隐藏此div。
Any kind of help will be appreciated. 任何帮助将不胜感激。
您可以为您的元素设置一个id,并使用document.getElementById来获取它,然后相应地对其进行更新。
Yes, there is a better way to get the child (and also the parent). 是的,有一种更好的方法来获得孩子(还有父母)。 I would set a unique class on all the clickable
<a>
tags which trigger your code so that you can assign the event handlers by class. 我会在所有可触发的
<a>
标记上设置一个唯一的类,这些类会触发您的代码,以便您可以按类分配事件处理程序。
$(".uniqueClass").click(function (e) {
var $div = $(this).parent();
var $deletedField = $div.find("input").first();
$deletedField.val(true);
});
Now you can get rid of all those ID attributes. 现在,您可以摆脱所有这些ID属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.