4

我对 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 目的:获取唯一元素的数组,每列一个
返回:数组 node:aReturn - 唯一元素列表
输入:object:oSettings - dataTables 设置对象
node:nHeader - 自动检测来自该节点的布局 - 可选
数组对象:aLayout - 来自 _fnDetectHeader 的 thead/tfoot 布局 - 可选

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++;
    }
}
4

3 回答 3

9

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

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

您在最后一个条目上留下了逗号。我犯了同样的错误,它至少在 Firefox 上运行良好,但不是 IE 8。

于 2011-11-22T18:45:06.993 回答
2

使用此代码为我解决了问题,我将问题悬而未决,也许有人知道为什么它适用于此更改。

"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
],
于 2011-07-28T11:13:57.140 回答
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>
于 2015-04-15T17:43:24.903 回答