확인 대화 상자는 대부분 옵션에 대한 사용자의 동의를 받는 데 사용됩니다. 두 개의 버튼이 있는 대화 상자가 표시됩니다. 취소 .
사용자가 확인 버튼을 클릭하면 창 방식이 확인됩니다. () true를 반환합니다. 사용자가 취소 버튼을 클릭하면 Confirm()이 false를 반환합니다.
예시
다음 코드를 실행하여 JavaScript에서 확인 대화 상자를 구현할 수 있습니다.
라이브 데모
<html>
<head>
<script>
<!--
function getConfirmation(){
var retVal = confirm("Do you want to continue ?");
if( retVal == true ){
document.write ("User wants to continue!");
return true;
}
else{
document.write ("User does not want to continue!");
return false;
}
}
//-->
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="getConfirmation();" />
</form>
</body>
</html>