alert message prompt box:
For warning, only OK button.
alert(str);
confirm message dialog:
The return value can be used to determine what button the user clicked 。
confirm(str);
Returns true when the user clicks the OK button.
Returns false when the user clicks the "Cancel" button.
prompt() message input box:
The pop-up box contains an input box and a confirmation cancel button, and the user can enter content in the input box.
var reason = (“Please enter a reason for failure to pass the review:”, “”); //1. Simply determine whether the user fills in the "Reason for Failure to Pass the Review":if(reason){ //The user filled in the reason}else{ //The user has no reason to fill in} //2. To distinguish whether the user clicks "OK" or "Cancel" without typing:if(reason){ alert(reason);//Show input content//The user has filled in the content and clicked "OK"}else if(reason === “”){ //The user did not enter the content and clicked "OK"}else{ //Click "Cancel"}
Supplement: 3 basic pop-up boxes of js
3 basic pop-up boxes of js:
1. Prompt box (warning box): alert("content");
There is a confirm button on the pop-up box, no return value
Example: alert("Box content!")
2. Confirm box: confirm("prompt content");
There are 2 buttons in the pop-up box: OK/Cancel
Click OK to return true, click Cancel to return false
Example 1: confirm("Prompt Content")
Example 2: <a href="" οnclick="return confirm('Do you want to visit Taobao?')">Go to Taobao</a>
3. Input box: prompt(parameter);
Parameter 1: Prompt statement. Default silent
Parameter 2: Default value. Different browsers have different default values.
Return value type is string
Input box example:
<script> // var str = prompt(); var str = prompt("Please enter your name", ""); ("You entered:" + str); </script>
This is the article about JS message pop-up alert, confirm, and propt. For more related JS message pop-up alert content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!