语法错误,解析tr元素时无法识别的表达式

uid 发布于 2019-03-09 jquery 最后更新 2019-03-09 14:38 3 浏览

我正在做一个jQuery中的$.post(),并接收一个<tr>元素作为响应,类似于:

<tr class="editable" id="527a84eb-b430-4a33-9079-a19d00ca373c">
    <td class="date">2013-04-05
    </td>
    <td class="amountType">Credit
    </td>
    <td class="amount">$5.00
    </td>
    <td class="category">Meals
    </td>
    <td class="notes"></td>
    <td data-expense-report-line-item-id="527a84eb-b430-4a33-9079-a19d00ca373c" class="actionItems">
        <button class="deleteLineItem">Delete</button>
        <button class="editLineItem">Edit</button>
    </td>
</tr>
我打算用这个函数在我的表中注入这一行:
$.post('@Url.Content("~/ExpenseReports/SaveLineItem")', {
    Date: date,
    Amount: amount,
    AmountType: amountType,
    ExpenseCategoryId: category,
    Notes: notes,
    ExpenseReportId: expenseReportId,
    ExpenseReportLineItemId: expenseReportLineItemId
}, function (data) {
    if ($('table tbody').length > 1) {
        $('table tbody tr:last').slideUp(200, function () {
            $(data).insertAfter('table tbody tr:first').slideDown();
        });
    } else {
        alert(data);
        $(data).appendTo($('table tbody'));
    }
    row.find('td.date:first input.date').val('');
    row.find('td.amount:first input.amount').val('');
    row.find('td.amountType:first select.amountType').val('Debit');
    row.find('td.category:first select.category').val('');
    row.find('td.notes:first input.notes').val('');
}, 'html');
这里的意图是在tbody元素的第一行之后插入这一行。但是,当我尝试这个时,我得到一个JavaScript错误:
Uncaught Error: Syntax error, unrecognized expression: <tr class="editable" id="527a84eb-b430-4a33-9079-a19d00ca373c">
        <td class="date">
            2013-04-05
        </td>
        <td class="amountType">
            Credit
        </td>
        <td class="amount">
            $5.00
        </td>
        <td class="category">
            Meals
        </td>
        <td class="notes">
</td>
        <td data-expense-report-line-item-id="527a84eb-b430-4a33-9079-a19d00ca373c" class="actionItems">
            <button class="deleteLineItem">Delete</button>
            <button class="editLineItem">Edit</button>
        </td>
    </tr> 
在我看来,这应该可以通过jQuery解析。我究竟做错了什么?
已邀请:

iaut

赞同来自:

问题是因为jQuery 1.9,1.10.2它运行得很好