The use method of JS confirm () Method Example _javascript skill

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.