"JavaScript" exception error

Source: Internet
Author: User

<!DOCTYPE HTML><HTML><Head>  <MetaCharSet= "Utf-8">  <title>JS Bin</title>  <Scripttype= "Text/javascript">window.onload= function(){        varRow=Document.createelement ("TR"); document.getElementById ("tbody"). appendchild (row);  }; </Script></Head><Body> <table></table>      <tbody  id= "tbody"></tbody>     </Body></HTML>

Each browser will report a different error (caused by the wrong tag nesting , need to put tbody in the table)

+| IE 6,7,8   | A method or property access was called unexpectedly.                                                                   | 0      |+| IE 9       cannot get the value of the property "AppendChild": object is null or     undefined                                      | 0      |+| IE      | Unable to get properties for undefined or null reference "AppendChild"                                                | 0      |+| Chrome  | Uncaught Typeerror:cannot Call method ' appendchild ' of null                                   |        | +| Safari 6   | TypeError: ' null ' is not a object (evaluating ' document.getElementById ("Tbody"). AppendChild ') |        | +| Firefox 21 | TypeError:document.getElementById (...) is null                                                |        | +| Opera   | uncaught exception:TypeError:Cannot convert ' document.getElementById ("tbody") ' to Object     |        |

Second, Li node set the Value property (you can set other properties instead)

<!DOCTYPE HTML><HTML><Head>  <MetaCharSet= "Utf-8">  <title>JS Bin</title><Scripttype= "Text/javascript">window.onload= function() {document.getElementById ("btn-test"). onclick = function(){      varul=Document.createelement ("ul"); varLi=Document.createelement ("Li"); //The following two lines of code will trigger an exception     //Li.value = "one";li.setAttribute("value"," One");      Ul.appendchild (LI);    Document.body.appendChild (UL);  }; };</Script></Head><Body> <button  id= "btn-test"> Click Start Test </button  > </Body></HTML>

Known IE6, IE7 can cause the browser to crash .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.