Wu Yuxiong - natural born JAVASCRIPT development of learning: Error - throw, try and catch

<! DOCTYPE HTML > 
< HTML > 
< head > 
< Meta charset = "UTF-. 8" > 
< title > novice tutorial (runoob.com) </ title > 
< Script > 
var TXT = "" ;
 function Message () {
     the try { 
        adddlert ( " available for purchase Guest! " ); 
    } 
    the catch (ERR) { 
        TXT = " page there is an error \ n-\ n-. " ;
        txt+ = " Error Description: "  + err.message +  " \ n-\ n- " ; 
        TXT + = " Click OK to continue \ n-\ n-. " ; 
        Alert (TXT); 
    } 
} 
</ Script > 
</ head > 
< body > 

< INPUT type = "Button" value = "view message" the onclick = "message ()"  /> 

</ body > 
</ HTML >

<! DOCTYPE HTML > 
< HTML > 
< head > 
< Meta charset = "UTF-8" > 
< title > newbie tutorial (runoob.com) </ title > 
</ head > 
< body > 
< the p- > regardless of the input is correct, input box will be emptied after re-entry. </ P > 
< P > Please enter a number between 10 ~. 5: </ P > 

< INPUT ID = "Demo" type = "text" > 
<="button" onclick="myFunction()">点我</button>

<p id="p01"></p>

<script>
function myFunction() {
  var message, x;
  message = document.getElementById("p01");
  message.innerHTML = "";
  x = document.getElementById("demo").value;
  try { 
    if(x == "") the throw  " value is empty " ;
     IF (isNaN (X)) the throw  " value is not a number " ; 
    X = Number The (X);
     IF (X >  10 ) the throw  " too large " ;
     IF (X <  . 5 ) the throw  " too small " ; 
  } 
  the catch (ERR) { 
    message.innerHTML =  " error: "  + ERR +  " . " ;
  }
  finally {
    document.getElementById("demo").value = "";
  }
}
</script>

</body>
</html>

<! DOCTYPE HTML > 
< HTML > 
< head > 
< Meta charset = "UTF-. 8" > 
< title > novice tutorial (runoob.com) </ title > 
</ head > 
< body > 

< P > Please 5 to output a a number between 10: </ P > 

< INPUT ID = "Demo" type = "text" > 
< Button type = "Button" the onclick = "myFunction () " > test input </button>
<p id="message"></p>

<script>
function myFunction() {
    var message, x;
    message = document.getElementById("message");
    message.innerHTML = "";
    x = document.getElementById("demo").value;
    try { 
        if(x == "")  throw "值为空";
        if(isNaN(x)) throw "不是数字";
        x = Number(x);
        if(x < 5)    throw "太小";
        if(x > 10)   throw "太大";
    }
    catch(err) {
        message.innerHTML = "错误: " + err;
    }
}
</script>

</body>
</html>

 

Guess you like

Origin www.cnblogs.com/tszr/p/10942709.html