IE shows run time error for innerHTML

后端 未结 9 1993
谎友^
谎友^ 2020-12-11 09:54

I have a jsp page in which rows are created dynamically to a table using java script. It is working fine in all the browsers except IE. In IE it is showing the error Unknown

9条回答
  •  时光说笑
    2020-12-11 10:27

    Never ever! Never use this kind of approach. This is very incorrect to concat a string and append as innerHTML. The better way is to use the native JavaScript DOM api for dom manipulation.

    Here the example of a working fiddle.

    EDIT

    I've tested it in IE9 but it should work in other IE versions too. The reason you cannot do it is that XHTML specification prohibit modifying the innerHTML property of certain tags. One of them is select tag. You cannot modify the internal options with innerHTML. As I see this is applicable to table either.

    Starting here, this is a very good point to refer to some library that has established itself as reliable dom manipulator. For example jQuery.

    If you want something to be done well, do it using jQuery.

提交回复
热议问题