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

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

问题描述

我有一个非常复杂的实现一个旧的infragistics UltraWebGrid。其中我试图强制进入浏览器兼容性,即使他们只是告诉我升级。我的网格不为非IE浏览器的某个网格呈现行。我跟踪错误到一些内置的javascript,我将在下面添加。我想我可以强制网格工作,在它尝试渲染动态添加的行之前添加一个tbody元素到grid html表。我的理念是这样的。我将如何做这个?

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?

这个问题,只有IE自动将tbody元素广告到空表。其他浏览器至少需要一行来存储tbody元素。似乎阻止这个网格呈现的javascript错误是无法获取主网格表的tbody元素。这应该能够通过强制tbody元素在表中通过javascript固定,如果浏览器是IE以外的任何东西。

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.

旧的infragistics网格内置的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;


推荐答案

顶端。检查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天全站免登陆