我在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可以解析的。我做错了什么?
答案 0 :(得分:0)
问题是因为jQuery 1.9,1.10.2它的效果很好