'style'为null或不是对象

时间:2011-07-28 10:09:18

标签: javascript jquery-datatables

我在datatables.net和Internet Explorer 8上遇到了一些问题(也可能是其他浏览器,但在IE9中有效)。我花了一些时间试图找出问题是什么,我一直无法解决,但我已经找到了似乎触发它的javascript:

如果我删除此代码然后它在IE 8中工作,有人可以用我的方式指出错误吗?

"aoColumns": [
    { "sType": "string" },                       // Player name
    { "sType": "numeric-minus" },                       // Damage done
    { "sType": "numeric-comma", "bVisible": false },    // DPS real
    { "sType": "numeric-comma" },                       // DPS Avg
    {"sType": "numeric-minus" },                        // Damage taken
    {"sType": "numeric-minus" },                        // Healing done
    {"sType": "numeric-comma", "bVisible": false },    // healing done HPS
    {"sType": "numeric-comma" },    // healing done HPS Avg
    { "sType": "numeric-comma" },                       // Overhealing
    { "sType": "numeric-comma" },                       // Healing taken
    { "sType": "numeric-comma", "bVisible": false },    // Mana done
    { "sType": "numeric-comma", "bVisible": false },    // Stamina done
    {"sType": "string", "bVisible": false },            // Class
    {"sType": "percent" },                              // Activity
],

IE 8的错误详情     网页错误详情

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
Timestamp: Thu, 28 Jul 2011 09:59:45 UTC    

Message: 'style' is null or not an object
Line: 5585
Char: 7
Code: 0
media/js/jquery.dataTables.js

数据表周围的行错误(错误行后面有注释)。

  

功能:_fnGetUniqueThs目的:获取一个独特的数组   元素,每列一个
返回:数组节点:aReturn - 列表   唯一的输入:对象:oSettings - dataTables设置   object
node:nHeader - 自动检测布局   node - 可选的数组对象:aLayout - 来自的thead / tfoot布局   _fnDetectHeader - 可选

var nThs = _fnGetUniqueThs( oSettings, nTheadClone );
iCorrector = 0;
for ( i=0 ; i<iColums ; i++ )
{
    var oColumn = oSettings.aoColumns[i];
    if ( oColumn.bVisible && oColumn.sWidthOrig !== null && oColumn.sWidthOrig !== "" )
    {
        nThs[i-iCorrector].style.width = _fnStringToCss( oColumn.sWidthOrig );
    }
    else if ( oColumn.bVisible )
    {
        nThs[i-iCorrector].style.width = ""; // This is the error line
    }
    else
    {
        iCorrector++;
    }
}

3 个答案:

答案 0 :(得分:9)

问题很可能是aoColumns数组中的最后一个对象:

    {"sType": "percent" },   
],

你在最后一个条目上留下了逗号。我犯了同样的错误,至少在Firefox上工作愉快,但不是IE 8。

答案 1 :(得分:2)

使用此代码为我解决了问题,我将问题保持打开状态,或许somone知道为什么它适用于此更改。

"aoColumns": [
    { "sType": "string", "sWidth": "auto" },                       // Player name
    {"sType": "numeric-minus", "sWidth": "auto" },                       // Damage done
    {"sType": "numeric-comma", "bVisible": false, "sWidth": "auto" },    // DPS real
    {"sType": "numeric-comma", "sWidth": "auto" },                       // DPS Avg
    {"sType": "numeric-minus", "sWidth": "auto" },                        // Damage taken
    {"sType": "numeric-minus", "sWidth": "auto" },                        // Healing done
    {"sType": "numeric-comma", "bVisible": false, "sWidth": "auto" },    // healing done HPS
    {"sType": "numeric-comma", "sWidth": "auto" },    // healing done HPS Avg
    {"sType": "numeric-comma", "sWidth": "auto" },                       // Overhealing
    {"sType": "numeric-comma", "sWidth": "auto" },                       // Healing taken
    {"sType": "numeric-comma", "bVisible": false, "sWidth": "auto" },    // Mana done
    {"sType": "numeric-comma", "bVisible": false, "sWidth": "auto" },    // Stamina done
    {"sType": "string", "bVisible": false, "sWidth": "auto" },            // Class
    {"sType": "percent", "sWidth": "auto" }                              // Activity
],

答案 2 :(得分:0)

在我的情况下使用表中的width="100%"导致问题,删除宽度解决了它。

工作代码

<table id="dt_table">
<thead>
<tr>
    <th>column1</th>
    <th>column2</th>
    <th>column3</th>
    <th>column4</th>
    <th>column5</th>
    <th>column6</th>
</tr>
</thead>
</table>