【问题标题】:Javascript's setExpression is the biggest problem for me. Any solution to overcome thisJavascript set Expression 对我来说是最大的问题。克服这个问题的任何解决方案
【发布时间】: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


    【解决方案1】:

    同样认为最好使用 jQuery 并使用 jQuery 完成相同的工作,该工作将适用于所有浏览器并删除 setExpression。

    类似:

    var MyMainControl = $(".StyleOf");
    MyMainControl.attr("top", MyMainControl.parent(".TheKeeper").offset().top );
    

    或者如果你有很多

    jQuery(document).ready(function() 
    {
        jQuery(".StyleOf").each(function(i, selected) {
            var MyMainControl = $(selected);
            MyMainControl.attr("top", MyMainControl.parent(".TheKeeper").offset().top );
        }
    }
    

    我认为 html 类似于

    <div class="TheKeeper">
     <div>
       <div>
         <div class="StyleOf"></div>
       </div>
      </div>
    </div>
    

    setExpression 用于使 css 与 ie6 兼容。

    当然你可以得到一些其他准备好的标题网格... :)

    【讨论】:

    • 我对 jquery 也一无所知。你能提供一些相同的表达方式
    【解决方案2】:

    您应该尝试使用http://fixedheadertable.com/ jQuery 插件。这应该可以消除任何跨浏览器问题,并且更具前瞻性。

    【讨论】:

      【解决方案3】:

      试试这个:

      for (x=0; x < trs.length; x++) 
      {
          trs[x].style.position = 'fixed';
          trs[x].style.top.setExpression = "this.offsetParent.scrollTop";
      }
      

      它对我有用!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-29
        • 2014-01-05
        • 2010-10-04
        • 1970-01-01
        • 1970-01-01
        • 2021-05-17
        • 2020-12-15
        相关资源
        最近更新 更多