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
    },
4

2 回答 2

2

我认为您的意思是使用this.id ==vs. $(this.id) ==。似乎错误也可能是因为this.id是空的(jQuery 会在 上抛出该错误$("#>"),但错误消息似乎也包含>,所以我不确定)。

于 2012-10-09T19:16:23.543 回答
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;
}
于 2012-10-09T20:08:35.683 回答