- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我像这样创建表格:
<table class="table" id="tbl_items">
<thead>
<tr>
<th>
Id
</th>
<th>
Item
</th>
<th>
Serial Key
</th>
<th>
Brand
</th>
<th>
Quantity
</th>
<th>
Description
</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
ViewBag.AccountID = item.AccountId.ToString();
if (item.Items != null)
{
foreach (var itemOnList in item.Items)
{
<tr>
<td class="cls-itemid" data-itemid="@itemOnList.ItemId">@Html.DisplayFor(model => itemOnList.ItemId)</td>
<td class="cls-itemname" data-itemname="@itemOnList.ItemName">@Html.EditorFor(model => itemOnList.ItemName)</td>
<td class="cls-serialnumber" data-serialnumber="@itemOnList.SerialNumber">@Html.EditorFor(model => itemOnList.SerialNumber)</td>
<td class="cls-brandname" data-brandname="@itemOnList.BrandName">@Html.EditorFor(model => itemOnList.BrandName)</td>
<td class="cls-quantity" data-quantity="@itemOnList.Quantity">@Html.EditorFor(model => itemOnList.Quantity)</td>
<td class="cls-description" data-description="@itemOnList.Description">@Html.EditorFor(model => itemOnList.Description)</td>
<td>
<a href="javascript:void(0);" data-itemid="@itemOnList.ItemId" class="btn_edit">Edit |</a>
<a href="javascript:void(0);" data-itemid="@itemOnList.ItemId" class="btn_delete">Delete</a>
</td>
</tr>
}
}
}
</tbody>
我正在尝试使用以下方法连续获取 td 的值:
$(".btn_edit").click(function() {
var row = $(this).closest("tr");
var text = row.find(".cls-itemname").text();
alert(text);
});
警告框没有任何值(value)。我无法使用数据项,因为当我更改 @Html.EditorFor 框的值时,它会给出旧值而不是新值。
最佳答案
自从您使用 @Html.DisplayFor()
返回 <input>
元素...我猜你想要输入的文本...
这会起作用:
$(".btn_edit").click(function() {
var row = $(this).closest("tr");
var text = row.find(".cls-itemname input").val(); // <-- Look the change here
alert(text);
});
.cls-itemname
中根本没有任何文字。元素...但是有一个 input
有一个 value
。使用 .val()
反对input
.
关于javascript - 使用 .closest 从 td 获取值并没有给出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46107209/
这个问题在这里已经有了答案: final keyword in method parameters [duplicate] (9 个回答) 关闭 8 年前。 在此示例中,声明 Object fina
我的目标:是通过我的函数更新字段获取选定值并使用函数输出值运行它。 问题:当我从列表中选择值时,它不会触发函数,也不会更新字段。 感谢您的帮助。 HTML 12 14 16 18 20 22 24
我有一本具有这种形式的字典: myDict = {'foo': bar, 'foobar baz': qux} 现在,我想拆分字典键中的空格,使其成为下一个键并获取值(重复)。 myDictRev1
vector a; vector b; int temp_holder; cout > temp_holder) a.push_back(temp_holder); cout > temp_h
Java 的开发过程中免不了与 Date 类型纠缠,准备总结一下项目经常使用的日期相关操作,JDK 版本 1.7,如果能够帮助大家节约那么几分钟起身活动一下,去泡杯咖啡,便是极好的,嘿嘿。当然,我
我正在使用 jquery ui 日期选择器来获取 fromDate 和 toDate 以下是from日期的代码 $("#from_date").datepicker({
我是一名优秀的程序员,十分优秀!