亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript ?? - ???, ????, ??

try ?? ?? ??? ??? ??????.

catch ? ?? ?????.

?? ?? ??? ?? ??? ?????.

JavaScript ??

JavaScript ??? JavaScript ??? ??? ? ??? ??? ??? ? ????.

?? ??? ? ????. ????? ?????? ?? ?? ??? ?????.

?? ????? ?? ??? ????? ? ????(???? ??? ??).

??? ???? ??? ???? ?? ??? ??? ? ????.

??, ??? ? ?? ?? ?? ???? ?? ??? ?? ????.

JavaScript?? ??? ?????

??? ????? ??? ???? ????? JavaScript ??? ???? ?? ???? ?????.

? ??? ???? ?? ??? ??? ????. JavaScript?? ??? ?????.

JavaScript try ? catch

try ?? ???? ?? ? ??? ????? ?? ??? ??? ? ????.

catch ?? ???? try ?? ???? ??? ??? ? ??? ?? ??? ??? ? ????.

JavaScript ?? try? catch? ??? ?????.

Syntax

try {
//??? ?? ??
} catch(err) {
//??? ?? ??
}

?:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<script type="text/javascript">
    function message()
    {
    try
    {
    adlert("Hello World!");
    }
    catch(err)
    {
    alert("錯(cuò)啦!");
    }
    }
</script>
</head>
<body>
  <input type = "button" value = "點(diǎn)擊" onclick = "message()">
</body>
</html>

Throw ?

throw ? ?? ?? ??? ?? ??? ?????.

??? ?? ??? ?? ?? ?? ?????.

try ? catch? ?? throw? ???? ???? ??? ???? ??? ?? ?? ???? ??? ? ????.

??

throw ??

??? JavaScript ???, ??, ??? ?? ??? ? ????.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php.cn</title>
<script>
function myFunction(){
try{ 
var x=document.getElementById("demo").value;
if(x=="")    throw "值為空";
if(isNaN(x)) throw "不是數(shù)字";
if(x>10)     throw "太大";
if(x<5)      throw "太小";
}
catch(err){
var y=document.getElementById("mess");
y.innerHTML="錯(cuò)誤:" + err + "。";
}
}
</script>
</head>
<body>
<p>請(qǐng)輸出一個(gè) 50 到 100 之間的數(shù)字:</p>
<input id="demo" type="text">
<button type="button" onclick="myFunction()">請(qǐng)輸入</button>
<p id="mess"></p>
</body>
</html>


???? ??
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> function message() { try { adlert("Hello World!"); } catch(err) { alert("錯(cuò)啦!"); } } </script> </head> <body> <input type = "button" value = "點(diǎn)擊" onclick = "message()"> </body> </html>