编程知识 cdmana.com

Three pop-up prompt boxes of JavaScript (alert, confirm, prompt)

Three kinds of prompt boxes

alert ()

alert() The method is to display a warning box with a prompt message and a confirmation button .
It should be noted that :alert() It's a blocking function , If we don't click the confirm button , The latter will not be loaded .

Usage mode :

alert(" The text you want to prompt ")

Sample code :

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script>
			alert(" This is the pop-up prompt text ")
		</script>
		<title></title>
	</head>
	<body>
		<p>alert It's a blocking function </p>
		<p> This sentence will only be displayed after confirming the prompt text in the pop-up box </p>
	</body>
</html>

Effect screenshots :

 Insert picture description here

confirm()

confirm() The method is to display a confirmation box with the specified message and the confirm and Cancel buttons .
If you click " determine " return true, Otherwise return to false.

Usage mode :
Do not receive return value :

confirm(" Writing this way can directly show , Do not receive return value .")

Receive return value :

var x; 
var r=confirm(" Please press the button !");
if (r==true){
	x=" What you press is \" determine \" Button .";
}
else{
	x=" What you press is \" Cancel \" Button .";
}
document.write(x)

Sample code :

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script>
			//  Usage 1 
			confirm(" Writing this way can directly show , Do not receive return value .")
			
			//  Mode 2 
			var x; 
			var r=confirm(" Please press the button !");
			if (r==true){
    
    
				x=" What you press is \" determine \" Button .";
			}
			else{
    
    
				x=" What you press is \" Cancel \" Button .";
			}
			document.write(x)
		</script>
		<title></title>
	</head>
	<body>
	</body>
</html>

Effect screenshots :
 Insert picture description here

prompt ()

prompt() The method is to display a dialog box that prompts the user to input .
This method returns the string entered by the user .

Usage mode :

Do not display default text :

prompt(" Happy? ?"); //  This display can also be left blank , But there's no point in interaction .

Show default text :

var x; 
var name=prompt(" Please enter your name ","Keafmd"); 
if (name!=null && person!=""){ 
 x=" Hello ! " + name + ".";
 document.write(x)
} 

Sample code :

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script>
			// Mode one 
			prompt(" Happy? ?"); //  This display can also be left blank , But there's no point in interaction .
			
			// Mode two 
			var x; 
			var name=prompt(" Please enter your name ","Keafmd"); // Show default text  "Keafmd"
			if (name!=null && name!=""){
    
     
			 x=" Hello ! " + name + ".";
			 document.write(x)
			} 
		</script>
		<title></title>
	</head>
	<body>
	</body>
</html>

Effect screenshots :
 Insert picture description here
Writing is not easy to , After reading it, if it helps you , Thank you for your support !
If you're on the computer side , See... In the lower right corner “ One key, three links ” Did you? , That's right. Point it [ ha-ha ]

 Insert picture description here


come on. !

Joint efforts !

Keafmd

版权声明
本文为[osc_y65eb2q]所创,转载请带上原文链接,感谢

Scroll to Top