Run, my JavaScript (3), run javascript

Source: Internet
Author: User

Run, my JavaScript (3), run javascript
JavaScript exception capture 1. exception: an error occurs during execution, causing the program to stop running. 2. throw an exception: generate an error message. exception capture try {code block where an exception occurs} catch (err) {error message processing} For example:

try{str = function demo(){}}catch(err){alert(err);}demo();
Here, str is undefined, and the demo () function does not have a function body. What are the errors we have captured? Of course, we can also use the throw statement to customize an error. DOM1. Introduction: DOM (Document Object Model), an API2.DOM for HTML and XML documents depicts any HTML document as a structure composed of multiple layers of nodes, forming layers between nodes, form a tree structure. 3. The document node is the root node of each document. 4. The document element is the outermost element of the document. Other elements in the document are included in the document element, with only one document element. On the HTML page, 5. Node is called a class array object, which stores a group of ordered nodes. You can use the [index] and item (index) methods to access specific values.
1. nodes at the same level point to the same parent node 2. two adjacent nodes can use nextsibling () and previussibing () to draw out 3. all nodes have the same attributes. ownerdouments () can point to the document node DOM operation HTML1. when the page is loaded, the browser will create a Document Object Model for the page 2. search element: Search for id; search for Tag name3. change content, innerHTML4. change attribute 1. change HTML output stream Note: douments cannot be used after the document is loaded. write to overwrite this document
<Body> <button id = "btn" onclick = "demo () "> button </button> <p id =" pid "> Hello </p> <script> function demo () {var btn1 = document. getElementById ("btn"); pid. innerHTML = "World" ;}</script> </body>
DOM operation CSS1. change the CSS style
<style>    #div{        width: 100px;        height: 100px;        background-color: red;    }</style><body><div id="div">    hello world</div><script>    function demo(){        document.getElementById("div").style.backgroundColor = "blue";    }</script><button onclick="demo()">abc</button></body>
DOM Event 1. the DOMEventListener handle can abstract the unified method into event handles that do not overlap with each other. There are two handles in total: addEventListener (add event handle to the specified Element) and removeEventListener (remove the added handle) the JavaScript event stream describes the order of events received on the page. event bubbles are received by specific elements, and then gradually spread to the node of the least specific elements (from inside to outside, level by level) 2. the least specific node for event capture first accepts the event, and the most specific node should finally receive the event (from outside to inside, spread step by step) 3. event Processing HTML event processing: directly add the event to the HTML structure for DOM0-level event processing: assign a function to an event handler attribute, but overwrite the parent event, call DOM2-level event processing by ID: addEventListener (event name, event processing function, Boolean value) (Ps. true: Event capture; false: Event bubbling) IE event handler: attachEvent/detachEvent
<Body> <! -- HTML event processing --> <div> <button id = "btn1" onclick = "demo ()"> button </button> <script> function demo () {alert ("HTML event processing") ;}</script> </div> <! -- DOM0-level event processing --> <div> <button id = "btn1"> button </button> <script> var btn = document. getElementById ("btn1"); function demo () {alert ("DOM0 event processing");} btn. onclick = demo; </script> </div> <! -- DOM2-level event processing --> <div> <button id = "btn1"> button </button> <script> var btn = document. getElementById ("btn1 "). addEventListener ("click", demo); function demo () {alert ("DOM2-level event processing") ;}</script> </div> </body>

IE event processing is not described too much here.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.