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