Analysis of Several Usage Methods of Javascript confirm
- 2021-08-28 18:55:13
- OfStack
confirm function
The confirm function is used to provide validation by first displaying the information contained in a given message parameter and providing two optional answers, "ok" and "cancel", and then waiting for the user to select one of them. If the user selects "ok", return true;; Otherwise, if "cancel" is selected, false will be returned. The syntax format of this function is as follows:
window.confirm (message, ok, cancel)
It has three parameters, in which the parameter message is the prompt information in the form of string to be displayed; The parameter ok is also a string information for display, which can be "OK" or other text information indicating the meaning of OK, such as "I Agree", "I Like" and so on; Similarly, the parameter cancel is also string information for display, which can be "Cancel" text or other text information indicating the meaning of Cancel.
<script> var bln = window.confirm("确定吗?"); alert(bln) </script>
Or
Button. Attributes. Add ("onclick", "javascript: if (! confirm ('Are you sure you want to delete this system consultation? ')) {return false;} ") Button. Attributes. Add ("onclick", "javascript: return confirm ('Please run after login, do you want to login again now? ') ")For example: < a onclick = "javascript: if (! confirm ('Are you sure you want to delete the selected information? \ n This operation cannot be resumed! ')) {return false;} "href =" delhtml. asp? adid = < %=rs(" rel="external nofollow" adid")% > & type_oneid= < %=rs("type_oneid")% > " > < font color="green" > Delete < /font > < /a >
Examples:
Below are placed < head > < /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>
Below are placed < body > < /body > Medium
<a href="" onClick=" rel="external nofollow" rusure() ;return false;">来点击我</a>
Confirm the submission action with confirm, and submit the confirmation prompt
For example, when you click Rewrite in the guestbook, sometimes we hope to have a prompt to avoid mistakes. The code is as follows:
Method 1
<input name="Submit" type="submit" onClick="if(confirm('是否打开网页?')) location='http://www.05376.com'" value="打开">
Method 2
<input name="Reset" type="reset" onClick="return clearbutton()" value="重写"> <script type="text/javascript"> function clearbutton() { if (!confirm("确定要重写吗?")) return false; } </script>
The confirm () method the confirm () method displays a dialog box with a specified message and OK and Cancel buttons. Note: confirm () returns true if the user clicks OK. If you click the Cancel button, confirm () returns false 1:
The code is as follows:
<a href="javascript:if(confirm('确实要删除该内容吗?'))location='http://www.baidu.com'" rel="external nofollow" >弹出窗口</a>
2 species:
The code is as follows:
< script language="JavaScript" > function delete_confirm (e) {if (event. srcElement. outerText = = "Delete") {event. returnValue = confirm ("Delete is irreversible, are you sure you want to delete?");}} document. onclick = delete_confirm; < /script > < a href="Delete.aspx" rel="external nofollow" onClick="delete_confirm" > Delete < /a >
3 species:
The code is as follows:
if(window.confirm('你确定要取消交易吗?')){ //alert("确定"); return true; }else{ //alert("取消"); return false; }
4 species:
The code is as follows:
<script language="JavaScript"> function delete_confirm() <!--调用方法--> { event.returnValue = confirm("删除是不可恢复的,你确认要删除吗?"); } </script>
One simpler method that I often use myself is simpler:
The code is as follows:
<form name="form1" method="post" action="xxx.htm" onSubmit="javascript:return window.confirm('确认提交吗?')">