【发布时间】:2011-04-13 02:27:33
【问题描述】:
我试图在过去 2 天冻结我的 gridview 标题,并在 Stackoverflow 以及谷歌搜索中获得了 this 链接和许多其他链接。当我在 IE 6,7 和 IE8 的兼容模式下使用它时,这工作正常,但在正常模式下,此代码不起作用。
这行给了我一个错误。我想实现这个功能。
trs[x].style.setExpression("top", "this.parentElement.parentElement.parentElement.scrollTop + 'px'");
在阅读 cmets 时,我了解到 scrollableTable.js 使用了 setExpression 方法,该方法在 IE8 中已被弃用。
以前我对这个问题一无所知。我希望 setExpression 方法有一些替代方法。
如何在此代码中用其他替代方法替换 setExpression 方法
function ScrollableTable(tableEl, tableHeight, tableWidth) {
this.initIEengine = function() {
this.containerEl.style.overflowY = 'auto';
if (this.tableEl.parentElement.clientHeight - this.tableEl.offsetHeight < 0) {
this.tableEl.style.width = this.newWidth - this.scrollWidth + 'px';
} else {
this.containerEl.style.overflowY = 'hidden';
this.tableEl.style.width = this.newWidth + 'px';
}
if (this.thead) {
var trs = this.thead.getElementsByTagName('tr');
for (x = 0; x < trs.length; x++) {
trs[x].style.position = 'relative';
trs[x].style.setExpression("top", "this.parentElement.parentElement.parentElement.scrollTop + 'px'");
}
}
if (this.tfoot) {
var trs = this.tfoot.getElementsByTagName('tr');
for (x = 0; x < trs.length; x++) {
trs[x].style.position = 'relative';
trs[x].style.setExpression("bottom", "(this.parentElement.parentElement.offsetHeight - this.parentElement.parentElement.parentElement.clientHeight - this.parentElement.parentElement.parentElement.scrollTop) + 'px'");
}
}
eval("window.attachEvent('onresize', function () { document.getElementById('" + this.tableEl.id + "').style.visibility = 'hidden'; document.getElementById('" + this.tableEl.id + "').style.visibility = 'visible'; } )");
};
【问题讨论】:
标签: javascript asp.net jquery css internet-explorer