공백 만 입력하면 다음 프로그램에서 ex4
예외 This is not a valid number
을 표시하는 대신 예외 (value less than 5
)를 표시하지만 그 뒤에있는 논리를 이해할 수 없습니다.자바 스크립트 코드에서 흰 공백 잡기
<html>
<head>
<title></title>
<script type="text/javascript">
function promptCheck() {
var val=prompt("Enter a Number between 5 and 10","");
try {
if(val=="") {
throw "ex1";
}
else if(val<5) {
throw "ex2";
}
else if(val>10) {
throw "ex3";
}
else if(isNaN(val)) {
throw "ex4";
}
}
catch(err) {
if(err=="ex1") {
alert("You have not entered any value");
}
if(err=="ex2") {
alert("Value less than 5");
}
if(err=="ex3") {
alert("Value greater than 10");
}
if(err=="ex4") {
alert("This is not a valid number");
}
}
}
</script>
</head>
<body>
<input type="button" value="Bring Mouse on Me!" onmouseover="promptCheck()" />
</body>
</html>
예 ... 그게 문제입니다. – sandbox