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