Why does .html work and not innerHTML or appendChild

后端 未结 4 2064
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 11:30

I am trying to add an ajax response to a div (it\'s HTML code with tables, forms, etc).

In FF innerHTML works perfectly, but in IE it gives me an unkno

相关标签:
4条回答
  • 2020-12-18 11:56

    IE is fussy about changing <table>s from javascript. I've run into trouble before if I don't specify the table down to the last detail, including the <tbody> tag.

    0 讨论(0)
  • 2020-12-18 11:57

    I have same problem every day. Try with .innerText instad of .innerHTML, that will solve your problem. Answer is Javascript is parsed different in IE and FF.

    0 讨论(0)
  • 2020-12-18 12:01

    IE has several documented (pre | table (thead, tbody, tr, tfoot) | div | select) .innerHTML bugs.

    Thus libraries like jQuery abstract away those bugs for you by applying workarounds where needed for IE.

    As for your specific error... without seeing the code it is hard to tell.

    Setting the .innerHTML on pre's, certain div's, select's (if it does fail, will fail silently) but setting the .innerHTML on certain table elements (in certain versions of IE) will actually throw an error/exception.

    Note: The issue with setting the .innerHTML of a div is very specific in condition and only occurs in IE6 & IE7.

    0 讨论(0)
  • 2020-12-18 12:07

    Just use jQuery and forget about all the horrible cross browser problems - you won't go back!

    0 讨论(0)
提交回复
热议问题