JS Confirmation box confirm () Usage example detailed

Source: Internet
Author: User

First of all, we introduce the three ways to use JavaScript confirmation box, the following details

The first method: Easy to use , you can open the page after confirmation. The principle is also relatively clear. Mainly used to delete a single message confirmation.

?
12345678910 <SCRIPT LANGUAGE=javascript> function del() {  var msg = "您真的确定要删除吗?\n\n请确认!";  if (confirm(msg)==true){   return true;  }else{   return false;  } } </SCRIPT>

Call Method:

?
1 <ahref="del.php?id=123"onclick="javascript:return del()">删 除</a>

The second method: the principle is the same as above. JavaScript Delete Confirmation Box

?
1 <ahref="javascript:if(confirm(‘确实要删除吗?‘))location=‘jb51.php?id=‘">删除</a>

The third method: a confirmation prompt primarily for bulk deletion

?
1234567891011 <input name="Submit" type="submit" class="inputedit" value="删除" onclick="{if(confirm(‘确定纪录吗?‘)){  this.document.formname.submit();  return true;}return false; }"> <input name="按钮" type="button" ID="ok" onclick="{if(confirm(‘确定删除吗?‘)){ window.location=‘Action.asp?Action=Del& TableName=Item& ID=<%=ID%>‘; return true;}return false;}" value="删除栏目" />

Let's share an example:JS Confirmation box confirm () code example


Confirm () confirmation box in the Web page is more commonly used, of course, some of the aesthetic requirements of the higher Web page may need to customize such a function, the following to introduce the Window object of the Confirm () function of the use, the following counties look at a code instance, because nothing is more intuitive than this.

?
1234567891011121314151617181920212223 <!DOCTYPE html> <html> <head> <meta charset="gb2312"> <title>confirm()代码实例</title> <script type="text/javascript"> window.onload=function(){ var bt=document.getElementById("bt"); bt.onclick=function(){  if(confirm("真的要删除吗?")){   alert("点击了确认按钮");  }  else{   alert("点击了取消按钮");  } }}</script> </head> <body> <input type="button" id="bt" value="点击弹出确认框" /></body> </html>

The above code is a simple example of confirm, can clearly demonstrate the role of confirm (), the following to do some summary:
The parameter in the 1.confirm () function is the prompt for the confirmation box.
2. The return value of this function is Boolean, click OK, the return value is True, click the Cancel return value is False.

The above is about the JS confirmation box confirm () Usage examples, the content is very rich, I hope you like.

JS Confirmation box confirm () Usage example detailed

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.