Confirm () method
The confirm () method is used to display a dialog box with the specified message and OK and cancel buttons.
Note: If you click OK, confirm () returns true. If you click Cancel, confirm () returns false.
One type:
Copy codeThe Code is as follows:
<A href = "javascript: if (confirm ('Are you sure you want to delete this content? ') Location = 'HTTP: // www.baidu.com' "> dialog box </a>
Two types:
Copy codeThe Code is as follows:
<Script language = "JavaScript">
Function delete_confirm (e)
{
If (event. srcElement. outerText = "delete ")
{
Event. returnValue = confirm ("deletion is unrecoverable. Are you sure you want to delete it? ");
}
}
Document. onclick = delete_confirm;
</Script>
<A href = "Delete. aspx" onClick = "delete_confirm"> Delete </a>
Three types:
Copy codeThe Code is as follows:
If (window. confirm ('Are you sure you want to cancel the transaction? ')){
// Alert ("OK ");
Return true;
} Else {
// Alert ("cancel ");
Return false;
}
Four types:
Copy codeThe Code is as follows:
<Script language = "JavaScript">
Function delete_confirm () <! -- Call Method -->
{
Event. returnValue = confirm ("deletion is unrecoverable. Are you sure you want to delete it? ");
}
</Script>
I often use a simpler method.
, Simpler:
Copy codeThe Code is as follows:
<Form name = "form1" method = "post" action = "xxx.htm" onSubmit = "javascript: return window. confirm ('Are you sure you want to submit? ') ">