The use of JavaScript's confirm

Source: Internet
Author: User

Confirm function

The Confirm function provides a confirmation function that first displays the information contained in the given message parameter and provides two selectable answers to "OK" and "Cancel", and then waits for the user to select one of them. Returns true if the user selects "OK", otherwise false if "Cancel" is selected. The syntax format for this function is as follows:

Window.confirm (message, OK, cancel)

It has 3 parameters, in which the parameter message is a message to be displayed as a string, and the parameter OK is also used to display a string of information, which can be "OK", or other text information indicating the meaning of OK, such as "I Agree", "I like" and so on; The argument Cancel is also used to display the string information, either "Cancel" text or other textual information that represents the cancel meaning.

<script> var bln = window.confirm ("OK?"); Alert (bln) </script>

or Button.Attributes.Add ("onclick", "Javascript:if" (!confirm (' Are you sure you want to remove the system consulting? ') {return false;} ")

BUTTON.ATTRIBUTES.ADD ("onclick", "Javascript:return confirm (' Please run after landing, is it now re-login?") ‘)")

For example: <a onclick= "Javascript:if (" 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:

The following are placed in

<script>

function Rusure ()

{

Question = Confirm ("Do you really want to go into it?")

if (question! = "0")

{

window.open ("", "Test Announcement window", "width=340,height=163,toolbar=0,status=0,menubar=0,resize=0");

}

}

</script>

The following are placed in <body></body>

<a href= "" onclick= "rusure (); return false;" > To click on Me </a>

Confirm submit action with confirm, submit confirmation prompt

For example, when the guestbook click Rewrite, sometimes we want to have a hint, so as not to error operation. The code is as follows: Method one

<input name= "Submit" type= "Submit" onclick= "if" Confirm (' Do you want to open the Web page? ') location= ' http://www.05376.com ' "value=" open >

Method Two

<input name= "reset" type= "reset" onclick= "return Clearbutton ()" value= "rewrite" > <script type= "Text/javascript" > Function Clearbutton () {if (!confirm ("OK to override? ")) return false;} </script>

Source: http://blog.sina.com.cn/s/blog_492399a701000bzr.html

The Confirm () method confirm () method is used to display a dialog box with the specified message and OK and Cancel buttons. Description: If the user clicks the OK button, confirm () returns TRUE. If you click the Cancel button, confirm () returns false one:

The code is as follows:

<a href= "Javascript:if (Do you really want to delete this content? ') location= ' http://www.baidu.com ' > Popup </a>

Two kinds:

The code is as follows:

<script language= "JavaScript" > Function delete_confirm (e) {if (Event.srcElement.outerText = = "Delete") { Event.returnvalue = Confirm ("Delete is not recoverable, are you sure you want to delete it?") "); } } Document.onclick = delete_confirm; </script> <a href= "delete.aspx" onclick= "delete_confirm" > Delete </a>

Three kinds:

The 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 kinds:

The code is as follows:

<script language= "JavaScript" > Function delete_confirm () <!--call Method--{Event.returnvalue = confirm (" Delete is not recoverable, are you sure you want to delete it? "); } </script>

A simpler way that I used to do it myself, more simply:

The code is as follows:

<form name= "Form1" method= "Post" action= "xxx.htm" onsubmit= "Javascript:return window.confirm (' Confirm commit? ') ' >

Source: http://www.jb51.net/article/31600.htm

The use of JavaScript's confirm

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.