Javascript confirm, alert, prompt

Source: Internet
Author: User

confirm function

confirm functions are used to provide the confirmation function, it first displays the given message the parameter contains information and provides two optional answers " OK " and "cancel" , then wait for the user to select one of them. If you select "OK" Returns true ; otherwise, if you select "cancel" Returns false . The syntax format of this function is as follows:

Window. Confirm (message, OK, cancel)

It has 3 Parameters. Message Is the prompt information in the string format to be displayed; Parameter OK It is also a string information used to display, it can be "OK" , Or it can be another representation OK Text Information of meaning, such "I agree" , "I like" And so on. Cancel It is also used to display string information, which can be "Cancel" Text, or other representation Cancel Meaning text information.

<SCRIPT>
VaR bln = Window. Confirm ("Are you sure you want? ");
Alert (BLN)
</SCRIPT>

Or
Button. Attributes. Add ("onclick", "javascript: If (! Confirm ('Are you sure you want to delete this system for consultation?') {Return false ;}")

Button. Attributes. Add ("onclick", "javascript: Return confirm ('Run it after login. Do you want to log on again now?')")

For example, <a onclick = "javascript: If (! Confirm ('Are you sure you want to delete the selected information? "N this operation cannot be restored! ') {Return false;} "href =" delhtml. asp? ADid = <% = RS ("ADid") %> & type_oneid = <% = RS ("type_oneid ") %> "> <font color =" green "> Delete </font> </a>

Example:

Put the following<Head> Medium

<SCRIPT>

Function rusure ()

{

Question = confirm ("Are you sure you want to enter?? ")

If (question! = "0 ")

{

Window. Open ("","Test announcement window"," Width = 340, Height = 163, toolbar = 0, status = 0, menubar = 0, resize = 0 ");

}

}

</SCRIPT>

Put the following<Body> </body>Medium

<A href = "" onclick = "rusure (); Return false;">Click me</A>

Use confirm to confirm the submission action and submit the confirmation prompt

For example, when you click rewrite in the message book, sometimes we want a prompt to avoid mistakes.CodeAs follows:

Method 1

<Input name = "Submit" type = "Submit" onclick = "If (confirm ('Open webpage? ') Location = 'HTTP: // www.05376.com' "value =" open ">

Method 2

<Input name = "reset" type = "reset" onclick = "Return clearbutton ()" value = "Override">
<SCRIPT type = "text/JavaScript">
Function clearbutton ()
{
If (! Confirm ("are you sure you want to rewrite it? ") Return false;
}

</SCRIPT>

 

 

Window. Confirm has only one parameter. The prompt box is displayed. Press OK to return true; Press Cancel to return false.
<SCRIPT>
VaR bln = Window. Confirm ("OK? ");
Alert (BLN)
</SCRIPT>
Window. Alert parameter, only one, displays the information in the warning box; no return value.
<SCRIPT>
Window. Alert ("OK. ")
</SCRIPT>
Window. Prompt parameter. There are two parameters. The first parameter displays the information in the prompt input box. The second parameter is used to display the default value of the input box. Returned value: the value entered by the user.
<SCRIPT>
VaR STR = Window. Prompt ("enter the password", "password ")
Alert (STR );
</SCRIPT>

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.