<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
const input = confirm('accept?')
alert(input)
</script>
</head>
<body>
</body>
</html>
1. **`confirm('accept?')`**: This line calls the `confirm` method, which displays a dialog box with a message ('accept?') and two buttons, "OK" and "Cancel".
- If the user clicks "OK", `confirm` returns `true`.
- If the user clicks "Cancel", `confirm` returns `false`.
2. **`alert(input)`**: This line uses the `alert` method to display another dialog box showing the result of the `confirm` call. This means it will display `true` if the user clicked "OK" on the first dialog, and `false` if they clicked "Cancel".
### How It Works:
- When a user navigates to a webpage containing this script, they are immediately presented with a confirmation dialog asking "accept?".
- Depending on the user's choice, an alert dialog will then show the boolean result of that choice: `true` for acceptance (OK) and `false` for rejection (Cancel).
### Use Case:
This simple interaction can serve as a basic method for user confirmation in web pages, often used for confirming actions such as form submissions, deletions, or any operation that requires user verification before proceeding.
'개념 > 혼자 공부하는 Javascript' 카테고리의 다른 글
function) apply() (0) | 2025.01.28 |
---|---|
function) prompt() (0) | 2025.01.26 |
class) generate object (0) | 2025.01.25 |
method) private (1) | 2025.01.24 |
class) Ractangle class (0) | 2025.01.23 |