javascript - Chrome 和 IE 中 InsertCell() 的区别

标签 javascript internet-explorer google-chrome insert cell

我正在 for 循环中将单元格添加到表格中,但结果在 ie 和 chrome 中不同。单元格的顺序相反。

比如;

IE [[cell_1][cell_2][cell_3][cell_4]]

Chrome [[cell_4][cell_3][cell_2][cell_1]]

为什么会发生这样的问题,有没有办法用其他方法(也许是 jQuery)添加单元格?

我使用ie 10.0.9chrome 30.0.1

<小时/>

更新:

您可以在两种浏览器中使用此代码进行尝试;

<html>
<head>
    <script type="text/javascript">
        function fillTable(){
            var aTBL = document.getElementById("table");

            aTR = aTBL.insertRow();

            for(i = 0; i < 5; i++){
                aTD = aTR.insertCell();
                aTD.innerHTML = "[cell_" + i + "]";
            }
        }
    </script>   
</head>
<body>
    <table id="table">
    </table>

    <script type="text/javascript">
        fillTable();
    </script>
</body>
</html>

最佳答案

如果您没有向 insertCell() 传递参数,那么浏览器在插入单元格的位置上似乎有不同的默认值。传递 -1 作为参数,然后将单元格附加到行的末尾。

aTD = aTR.insertCell(-1);

关于javascript - Chrome 和 IE 中 InsertCell() 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19950523/

相关文章:

javascript - WIX React-native-navigation v2 不会调用 registerAppLaunchedListener()

CSS:IE:样式版本 "background-color:rgba(...)"

javascript - 使用 Chrome 的 JavaScript 控制台关闭特定网站的所有选项卡

html - chrome如何检测登录文本框?

android - 如何在隐身标签中打开chrome

javascript - 为 IBM BPM 表创建全选控件

javascript - MVC 从下拉列表中过滤 actionResult

html - 下拉 IE 8 及以下版本不工作

javascript - 在 Internet Explorer 上运行 js 的问题

javascript - AmPieChart 值和百分比