If the user clicks the OK button, confirm () returns TRUE. If you click the Cancel button, confirm () returns false.
Before the user clicks the OK button or the Cancel button closes the dialog box, it blocks all input from the user to the browser. When confirm () is invoked, execution of the JavaScript code is paused, and the next statement is not executed until the user responds.
Let's take a look at these two small examples to see how it is used:
Copy Code code as follows:
How to use <title>confrim </title>
<script type= "Text/javascript" >
function Clear1 ()
{
if (confirm) are you sure you want to empty the data? "))
{
Document.main.text1.value= "";
}
}
</script>
<boty>
<form name= "Main" >
<input type= "text" name= "Text1"/>
<input type= "button" name= "Submit" value= "Data Empty" onclick= "return clear1 ()"/>
</form>
</body>
<title>js confirm</title>
<script>
Function begin ()
{
var a=confirm ("Guo Yang and Xiao Dai are good friends?") ");
if (a==true)
{
/*document.write ("Congratulations!") ");*/
Alert ("Congratulations on your answer!") ");
Begin ();
}
Else
{
/*document.write ("You are a pig, such a simple question will not answer!" ");*/
Alert ("You're such a pig, you can't answer that simple question!") ");
Begin ();
}
}
</script>
<body onload= "Begin ()" >
</body>