2013-04-11 60 views
1

我在jQuery的做$.post()和響應接收<tr>元素時,類似於此:語法錯誤,無法識別的表達式分析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

我不認爲'' S可向下滑動,但不會是你正在尋找 – 2013-04-11 16:33:05

+1

使用Firebug的問題在這裏(所以無論版本的jQuery SO使用)它解析你的HTML罰款(跑''(' ..你的東西..)') – Mikeb 2013-04-11 16:34:51

+0

嗯......我想知道這是否是Chrome的問題.. 。 – 2013-04-11 16:38:23

回答

0

問題是因爲jQuery 1.9,與1.10.2它工作得很好

相關問題