zoukankan      html  css  js  c++  java
  • innerHTML未知的运行错误

    代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        
    <title>innerHTML未知的运行错误</title>
    </head>
    <body>
    <id="p"></p>
    <script type="text/javascript">
        
    var p=document.getElementById('p');
        p.innerHTML
    ='<div>innerHTML简单易用,不过</div>';
    </script>
    </body>
    </html>

    运行以上代码,IE里提示:未知的运行错误。FF测试是正确的。
    Goole一下,innerHTML 对下面的对象只读(<=IE7):table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset等。

    上面所说的innerHTML属性只读的对象中并不包括p,为什么还报错。
    再google,找到这么一段:

    The <p> tag can be nested within certain tags and certain tags can be nested within it. The general rule is that the paragraph has to be its own block. Therefore, a paragraph tag cannot be nested within a tag expecting only text or inline elements, nor can another block element tag be nested within a paragraph tag.
    For instance, you cannot nest paragraph tags and heading tags.
    You can also put paragraph tags within division tags but not the other way around.
    A paragraph tag can be placed within a table cell or other tags structures that are not text only. It can also be placed within a list item. This means you can have long, multi-paragraph list items. Anything can be nested within a <p> tag that is allowed within the flow of the text. All style tags are allowed within a paragraph since they format text. Links and images can be placed within paragraphs, and the <br /> tag exists for the exclusive purpose of breaking the line without ending the paragraph.
    If a Web browser encounters a tag within a paragraph that cannot be nested within paragraph tags, it will assume that the paragraph has ended.

    大家自己看吧, 其中的大意之一:p标签不能包容div、h1除了<br />等块级元素。

    所以IE报未知的运行错误原因就是innerHTML里有div标签,另外往p元素里插入div元素也会失败 【p.appendChild(div)】
    最后,蓝色理想上的一篇blank的“innerHTML的一些问题”。

  • 相关阅读:
    git 重命名文件夹
    关于IDEA的Incoming窗口的问题
    mysql替换字段中部分字符串
    IDEA项目改包名改项目名并启动【我】
    IDEA在自带市场安装黑色主题及调整包管理器字体大小【我】
    解决Invalid bound statement (not found)(Mybatis的Mapper绑定问题)
    java中Date日期类型的大小比较
    MyBatis-Plus Wrapper条件构造器查询大全
    idea黑色主题
    python3安装mysqlclient,解决django使用pymysql报错的问题
  • 原文地址:https://www.cnblogs.com/orc/p/1224322.html
Copyright © 2011-2022 走看看