JavaScript Learning Note (V): Exception capture and event handling

Source: Internet
Author: User

Exception capture

try{

The code block where the exception occurred

}catch (Err) {

Exception handling

}

1 <!DOCTYPE HTML>2 <HTML>3 <HeadLang= "en">4     <MetaChaset= "UTF-8">5     <title></title>    6 </Head>    7 <Body>8     <form>9         <inputID= "txt"type= "text">Ten         <inputID= "BTN"type= "button"onclick= "Demo ()"value= "button"> One     </form> A     <Script> -         functionDemo () { -             Try{ the                 vare=document.getElementById ("txt"). Value; -                 if(e==""){ -                     Throw "Please enter"; //General throw will be used in conjunction with Try,catch -                 } +             }Catch(err) { - alert (err); +             } A         } at     </Script> - </Body> - </HTML>

Event handling

1. onclick Mouse click event

2. onmouseout Mouse Leave Event

3. onmouseover Mouse over Event

4. onchange text box content Change Event

5. onselect text Box Contents Check Event

6. onfocus Cursor Aggregation Event

7. onload page Loading Complete event

1 <!DOCTYPE HTML>2 <HTML>3 <HeadLang= "en">4     <MetaChaset= "UTF-8">5     <title></title>    6     <Linkrel= "stylesheet"type= "Text/css"href= "Style.css"> <!--specify REL as style sheet, CSS type, external file style.css -7 </Head>    8 <Bodyonload= "OnLoad ()">                         <!--onload page load Complete event -9     <Buttononclick= "OnClick ()">Button</Button>             <!--onclick Mouse click event -Ten     <Divclass= "Div"onmouseout= "Onout (this)"onmouseover= "Onover (this)"></Div> <!--onmouseout Mouse out event, onmouseover mouse over event - One     <form> A         <inputtype= "text"onchange= "OnChange (this)">       <!--onchange text Box content Change Event - -         <BR> -         <inputtype= "text"onselect= "OnSelect (this)"onfocus= "onfocus (this)">   <!--onselect text box content Check event, onfocus Cursor aggregation event - the     </form>     -     <Script> -         functionOnClick () { - Alert ("onclick Mouse click"); +         } -         functionOnover (ooj) { + ooj.innerhtml="onmouseover Mouse over"; A         } at         functionOnout (ooj) { - ooj.innerhtml="onmouseout Mouse Away"; -         }     -         functionOnChange (BG) { - Alert ("onchange text box content changes"); -         } in         functionOnSelect (BG) { - Bg.style.background="Yellow"; to Alert ("onselect text Box contents selected"); +         } -         functiononfocus (BG) { the Bg.style.background="Green"; * Alert ("onfocus Cursor Aggregation"); $         }Panax Notoginseng         functiononLoad () { - Alert ("onload Web page loading complete"); the         } +     </Script> A </Body> the </HTML>

JavaScript Learning Note (V): Exception capture and event handling

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.