Why is document.getElementById('tableId')[removed] not working in IE8?

前端 未结 8 2069
迷失自我
迷失自我 2020-12-01 14:17

I modify document.getElementById(\'\').innerHTML with Java Script in a page. It\'s working fine in Firefox, but not IE8. Please see below for more details:

8条回答
  •  北海茫月
    2020-12-01 14:47

    I believe IE behaves strangely when you play with the innerHTML of tr elements. I would select the row with getElementById, and then select the td and alter that one's innerHTML:

    document.getElementById('abc').firstChild.innerHTML = 'abc';
    

    (Though you have to be careful with this: often the whitespace between the tr and the td will be considered a valid node)

    There's a whole heap of special functions for working with tables in the DOM

    var tblBody = document.getElementById(tblId).tBodies[0];
    var newRow = tblBody.insertRow(-1);
    var newCell0 = newRow.insertCell(0);
    

    See all the functions here: http://www.mredkj.com/tutorials/tablebasics1.html

提交回复
热议问题