1

$.post()在 jQuery 中做一个并收到一个<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 解析。我究竟做错了什么?

4

1 回答 1

0

问题是因为 jQuery 1.9,使用 1.10.2 它工作得很好

于 2013-12-11T17:04:41.600 回答