JavaScript Learning (a) exception handling with simple events

Source: Internet
Author: User

One: Exception handling

  

<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <title></title></Head><Body>    <form>    <inputID= "txt"type= "text" />    <inputID= "BTN"type= "button"value= "Submit"onclick= "Demo2 ()" />    </form>    <Scripttype= "Text/javascript">        //System Error        functionDemo () {Try{alert (str); }            Catch(ERR) {alert (ERR); }        }        //Custom Error        functionDemo2 () {//here if you do not write try.    Catch..  Throw ("Text cannot be empty"); It's not going to pop.            Try {                vare=document.getElementById ("txt"). Value; if(e== "") {                    Throw ("text cannot be empty"); }            }            Catch(ERR) {alert (ERR); }        }    </Script></Body></HTML>

Two: Event handling:

<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <title></title>    <styletype= "Text/css">. Div{width:100px;Height:100px;Background-color:Blue;        }    </style></Head><Body>    <Divclass= "Div"onmouseover= "Onover (this)"onmouseout= "Onout (this)">    </Div>    <form>    <inputID= "txt"type= "text"onchange= "OnChange (this)" />    <inputID= "Txt2"type= "text"onselect= "OnSelect (this)"onfocus= "onfocus (this)"/>    </form>    <Scripttype= "Text/javascript">        functionOnover (e) {e.innerhtml= "Hello"; }        functionOnout (e) {e.innerhtml= " World"; }        functionOnChange (e) {alert ("content changed to:" +e.value)}functionOnSelect (e) {E.style.color= "Red"; }        functiononfocus (e) {E.style.color= "Black"; }    </Script></Body></HTML>

Effect:

1: When the mouse is no longer div

2: When the mouse is placed on the DIV

3: Change the value of txt when Li Peng:

4: When the value of Tex2 is selected: The result becomes:

5: Focus on TEX2: The result is:

JavaScript Learning (a) exception handling with simple events

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.