2012-10-09 104 views
2

我試圖從flexigrid獲取單元格的文本值。 但是我不斷收到該錯誤。未捕獲的錯誤:語法錯誤,無法識別的表達式:#

這是我的功能,用於檢索特定單元格的文本(Flexigrid不具有「attr」而是具有「abbr」)。

function getSelectedCopyDates() { 
    var arr = new Array(); 
    debugger; 
    //for every row that has a checked checkbox 
    $("tr").has(".noteCheckBox:checked").each(function(i) { 
     if ($(this.id) !== "checkAllNotes") { 
      //push the value of column(FName, LName) into the array 
      arr.push($("#" + this.id + "> td[abbr='EventDate'] > div").text()); 
     } 
    }); 
    return arr; 
} 

我只在點擊「checkAllNotes」(主複選框)時出現該錯誤。如果我手動檢查複選框,那麼一切工作正常。

這裏是我的flexigrid佈局:

$('#viewNotesGrid').flexigrid({ 
    url: url, 
    dataType: 'json', 
    method: 'get', 
    colModel: [{ 
     display: '<input type="checkbox" class="noteCheckBox" id="checkAllNotes" />', 
     name: 'checkBox', 
     width: 20, 
     sortable: false, 
     align: 'center', 
     process: showDescription 
    }, { 
     display: 'Date', 
     name: 'EventDate', 
     width: 80, 
     sortable: true, 
     align: 'center', 
     process: showDescription 
    }, 
+0

@TimMedora都能跟得上。 –

回答

2

第一個問題是,$("tr").has(".noteCheckBox:checked")返回tr元素,而不是輸入複選框。

第二個問題:$(this.id) !== "value"將無法​​工作。您正在創建jQuery對象並將其與字符串進行比較。應該是this.id !== "value"

第三個問題:已經在前面的答案中解釋過了。如果元素似乎沒有id,那麼"#" + this.id + ">將導致"#>",而您實際上想要比較特殊輸入字段的id,而不是tr。

使一些假設在這裏,但是這可能工作:

function getSelectedCopyDates() { 
var arr = new Array(); 

//for every row that has a checked checkbox 
$("tr .noteCheckBox:checked").each(function (i) { 
    if (this.id !== "checkAllNotes") { 
     var tr = $(this).parents("tr")[0]; // going back to parent tr 
     arr.push($(tr).find(" > td[abbr='EventDate'] > div").text()); 
    } 
}); 
return arr; 
} 
+0

非常感謝。我對jQuery不是很熟悉。然而這解釋了很多 – user1084319

2

我想你的意思是使用this.id ==$(this.id) ==。它也似乎是錯誤可能是因爲this.id是空的(jQuery將在$("#>")上拋出該錯誤,但錯誤消息也似乎包括>,所以我不確定)。

+0

如果我迭代選中的行,它怎麼會在空字符串上拋出異常。我的意思是我沒有if語句的功能完全正常,除了當我勾選「id = checkAllNotes」複選框。 – user1084319

+0

@ user1084319不知道;我猜其中一行缺少一個ID? –

+0

啊但事情是行沒有身份證。只有名爲「checkAllNotes」的複選框有一個ID。所有其他複選框只有attirbute ID(abbr不是attr,因爲它是一個flexigrid)。 「checkAllNotes」有一個類與所有其他複選框相同。 – user1084319

相關問題