insertRow在IE7中返回null [英] insertRow returns null in IE7
问题描述
var otbody = document.createElement('tbody');var otr = otbody.insertRow(ordernumber);otr.id ="order" +订单号;var pidCell = otr.insertCell(0);
在IE7中执行insertRow时发生错误.我使用IE9的IE7模式,并且otbody确实具有方法insertRow.我在调试器控制台中尝试使用0,-1、1等作为此方法的参数,但所有方法都返回null.当我使用document.createElement("tr")创建表行时,insertCell()返回null.我想知道这些用于处理表格的方法是否在所有浏览器上都能正常工作.
There is an error when insertRow is executed in IE7. I use IE9's IE7 mode, and otbody does have the method insertRow. I have tried 0, -1, 1 etc. as the argument of this method in debugger console, but all return null. And when I use document.createElement("tr") to create table row, insertCell() returns null. I wonder if these methods to deal with table work on all browser.
IE7 requires tbody attached to a table element to create tr, so you should create an extra table element, append the tbody element to table, than call insertRow on tbody element:
var otable = document.createElement('table');
var otbody = document.createElement('tbody');
otable.appendChild(otbody);
var otr = otbody.insertRow(0); // now otr will not be null
var otd = otr.insertCell(0); // and the same as tr element
这篇关于insertRow在IE7中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!