我在使用 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
错误周围的数据表行(错误行后面有注释)。
Function: _fnGetUniqueThs Purpose: Get an array of unique th elements, one for each column
Returns: array node:aReturn - list of unique ths
Inputs: object:oSettings - dataTables settings object
node:nHeader - automatically detect the layout from this node - optional
array object:aLayout - thead/tfoot layout from _fnDetectHeader - optional
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++;
}
}
最佳答案
问题很可能是 aoColumns 数组中的最后一个对象:
{"sType": "percent" },
],
您在最后一个条目上留下了逗号。我犯了同样的错误,它至少在 Firefox 上运行得很愉快,但在 IE 8 上却不行。
关于javascript - 'style' 为 null 或不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6857257/