Do you still remember the confirm message dialog box mentioned in the JavaScript introduction before? It doesn't matter if you don't remember it, let's review it first and then talk about it in detail.
review:
The confirm message dialog box is usually used to allow users to make choices, such as: "Are you right?" and so on. A dialog box pops up (including an OK button and a Cancel button).
grammar:
confirm(str);
Parameter description:
str: The text return value to be displayed in the message dialog box: Boolean value return value:
When the user clicks the "OK" button, return true. When the user clicks the "Cancel" button, return false Note: The return value can be used to determine what button the user clicked.
Look at the following code:
<script type="text/javascript"> var mymessage=confirm("Do you like JavaScript?"); if(mymessage==true) { document.write("Good, come on!"); } else { document.write("JS is powerful, you need to learn!"); }</script>result :
Note : The message dialog box is exclusive, that is, the user cannot perform any other operations before clicking the dialog button.
Task
Use the confirm() prompt box to complete gender confirmation when the button is clicked.
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>confirm</title> <script type="text/javascript"> function rec(){ var mymessage=confirm("You are a lady!"); if(mymessage==true) { document.write("You are a lady!"); } else { document.write("You are a man!"); } } </script></head><body> <input name="button" type="button" onClick="rec()" value="Click me and the confirmation dialog box pops up" /></body></html>result:
extend:
As mentioned before, it is best to write functions using functions, so that each function is a function. If these functions are used in the future, you can use them directly. That is to reuse. So get used to this. . . . . .
Just like the example above
<script language="JavaScript">function confirm (){ var msg=confirm("You are a lady!"); if(msg==true) { document.write("You are a lady!"); } else { document.write("You are a man!"); } } </script>Then call the function to input, add onClick="confirm ()" and finally make a summary of javascript window.confirm
The first type:
It's the method we mentioned above
<script language="JavaScript"> function confirm (){ var msg=confirm("You are a lady!"); if(msg==true) { document.write("You are a lady!"); } else { document.write("You are a man!"); } } </script><input name="button" type="button" onClick="confirm()" value="Click me and the confirmation dialog box will pop up" />
The second type:
In the tag:
1.
<a href="javascript:if(confirm('Do you really want to delete this content?')) location='#'">Delete</a>2.
<a href="#" onclick= "if(confirm( 'Do you really want to delete this content?')==false)return false; ">Click OK</a>
If you want to call it simply, it can be the same
The code is as follows:
<a href="#" onclick= "return confirm('Do you really want to delete this content?');">Delete</a>The third type:
<script language="JavaScript">function del_confirm(e){if (event.srcElement.outerText == "Delete"){event.returnValue = confirm("Delete is unrecoverable, are you sure you want to delete?");}} document.onclick = delete_confirm;</script><a href="#" onClick="del_confirm">Delete</a>
The fourth type:
<script language="JavaScript">function del_confirm(){event.returnValue = confirm("Deletion is not recoverable, are you sure you want to delete it?");}</script><a href="http://www.baidu.com" onClick="del_confirm()">Delete</a>
The above is the summary of the implementation method of the confirm confirm dialog box brought to you by the editor. I hope everyone will support Wulin.com more~