Javascript 使用从td获取值。最近值不提供值

Javascript 使用从td获取值。最近值不提供值,javascript,jquery,Javascript,Jquery,我这样创建表: <table class="table" id="tbl_items"> <thead> <tr> <th> Id </th> <th> Item </th> <th> Serial Key </th>

我这样创建表:

<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>
警报框没有值。我无法使用数据项,因为当我更改@Html.EditorFor框的值时,它给出的是旧值而不是新值。

因为您使用的是返回
元素的。。。我猜你想要输入的文本

这将有助于:

$(".btn_edit").click(function() {
  var row = $(this).closest("tr");
  var text = row.find(".cls-itemname input").val();  // <-- Look the change here
  alert(text);
});
$(“.btn\u编辑”)。单击(函数(){
var行=$(此).tr;
var text=row.find(“.cls itemname input”).val();//因为您使用了返回
元素的which…我想您希望输入的文本

这将有助于:

$(".btn_edit").click(function() {
  var row = $(this).closest("tr");
  var text = row.find(".cls-itemname input").val();  // <-- Look the change here
  alert(text);
});
$(“.btn\u编辑”)。单击(函数(){
var行=$(此).tr;

var text=row.find(“.cls itemname input”).val();//您是否检查了浏览器控制台是否有错误?我怀疑是否会显示任何错误,因为警报无疑会给出
未定义的
。可能是
console.log(row);
并查看控制台是否输出您期望的内容?然后转到
console.log(text)
如果
行的输出正确
.cls itemname
的内容不是一个输入控件(
@Html.EditorFor(model=>itemOnList.itemname)
)?您希望得到什么文本?当我使用console.log(行)和(文本)时,我没有收到任何错误,但是使用console.row()我得到了“单元格:(7)[td.cls-itemid,td.cls-itemname,td.cls-serialnumber,td.cls-brandname,td.cls-quantity,td.cls-description,td]“在console.log(text)上,它只是空白。您给定的代码对我有效:-(我认为您没有引起问题的
)。您能否显示呈现的html代码,而不是此foreach生成的代码。实际呈现的代码(通过问题中的inspect元素复制并粘贴)是否检查了浏览器控制台是否存在错误?我怀疑是否会显示任何错误,因为警报无疑会给出
未定义的
。可能
控制台.log(行)
并查看控制台是否输出您期望的内容?然后转到
控制台.log(text);
如果
行的输出正确
.cls itemname
的内容不是一个输入控件(
@Html.EditorFor(model=>itemOnList.itemname)
)?您希望得到什么文本?当我使用console.log(行)和(文本)时,我没有收到任何错误,但是使用console.row()我得到了console.log(文本)上的“单元格:(7)[td.cls-itemid,td.cls-itemname,td.cls-serialnumber,td.cls-brandname,td.cls-quantity,td.cls-description,td]”,它是空的。您给出的代码对我有用:-(我认为您没有引起问题的
)。您能否显示呈现的html代码,而不是每个生成的代码。实际呈现的代码(通过inspect元素复制并粘贴到问题中)