如何将tbody元素强制为非IE浏览器的空表 [英] How to force a tbody element into an empty table for non IE browsers

查看:122
本文介绍了如何将tbody元素强制为非IE浏览器的空表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的旧的infragistics UltraWebGrid的实现。我试图强制浏览器兼容性,即使他们只是告诉我升级。我的网格没有为非IE浏览器的特定网格呈现行。我已经跟踪了一些内置的JavaScript的错误,我将在下面添加。我想我可以通过在网格html表中添加一个tbody元素来强制网格,然后再尝试渲染动态添加的行。我的这个想法的逻辑如下。我该怎么做?

I have a pretty complex implementation of an old infragistics UltraWebGrid. Which I am trying to force into browser compatability, even though they just tell me to upgrade. My grid is not rendering rows for a certain grid for non IE browsers. I have traced the error to some built in javascript which I will add below. I think I can force the grid to work by adding a tbody element to the grids html table before It attempts to render the dynamically added rows. My logic for coming across this idea is below. How would I go about doing this?

根据这个SO问题,只有IE自动将tbody元素广告到空表。其他浏览器至少需要一行tbody元素存在。似乎阻止此网格渲染的JavaScript错误是无法获取主网格表的tbody元素。如果浏览器是IE以外的其他东西,可以通过javascript强制tbody元素来修复这个问题。

As per This SO question, only IE automatically ads a tbody element to an empty table. Other browsers require at least one row for a tbody element to exist. The javascript error that seems to be preventing this grid from rendering is the inability to get the tbody element of the main grid table. This should be able to be fixed by forcing a tbody element in the table via javascript if the browser is anything other than IE.

旧的内部网格内置JavaScript似乎假设这个tbody元素将在空格中。因此,我的页面无法加载非IE浏览器中的网格行,因为JavaScript正在调用不存在的元素。

The old infragistics grid's built in javascript seems to assume this tbody element will be there in an empty grid. Because of this, my page is unable to load the rows of the grid in non IE browsers because the javascript is calling an element that doesnt exist.

打破javascript:

Breaking javascript:

(这在非IE浏览器的最后一行打破,我假设因为没有tbody元素)

(this breaks at the last line for non IE browsers. I assume because there is no tbody element)

var strTransform = this.applyXslToNode(this.Node);
if (strTransform)
{
    var anId = (this.AddNewRow ? this.AddNewRow.Id : null);
    this.Grid._innerObj.innerHTML = "<table style=\"table-layout:fixed;\">" + strTransform + "</table>";
    var tbl = this.Element.parentNode;
    igtbl_replaceChild(tbl, this.Grid._innerObj.firstChild.firstChild, this.Element);
    igtbl_fixDOEXml();
    var _b = this.Band;
    var headerDiv = igtbl_getElementById(this.Grid.Id + "_hdiv");
    var footerDiv = igtbl_getElementById(this.Grid.Id + "_fdiv");
    if (this.AddNewRow)
    {
        if (_b.Index > 0 || _b.AddNewRowView == 1 && !headerDiv || _b.AddNewRowView == 2 && !footerDiv)
        {
            var anr = this.AddNewRow.Element;
            anr.parentNode.removeChild(anr);
            if (_b.AddNewRowView == 1 && tbl.tBodies[0].rows.length > 0)
                tbl.tBodies[0].insertBefore(anr, tbl.tBodies[0].rows[0]);
            else
                tbl.tBodies[0].appendChild(anr);
        }
        this.AddNewRow.Element = igtbl_getElementById(anId);
        this.AddNewRow.Element.Object = this.AddNewRow;
    }
    this.Element = tbl.tBodies[0];
    this.Element.Object = this;


推荐答案

我建议在设置innerHTML时添加tbody顶端。检查strTransform是否已经包含一个tbody,如果没有,请自己添加一个。如下所示:

I would recommend adding the tbody when you set innerHTML at the top. Check if strTransform already contains a tbody, and if it doesn't, add one yourself. Something like:

var tadd1 = '';
var tadd2 = '';
if (!(/\<tbody\>/.test(strTransform))) {
    tadd1 = '<tbody>';
    tadd2 = '</tbody>';
}
this.Grid._innerObj.innerHTML =
    "<table style=\"table-layout:fixed;\">" + tadd1 + strTransform + tadd2 + "</table>";

这篇关于如何将tbody元素强制为非IE浏览器的空表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆