<html> <head> <script type = "text/javascript"> function fun() { prompt ("This is a prompt box", "Hello world"); } </script> </head> <body> <p> Click the following button to see the effect </p> <form> <input type = "button" value = "Click me" onclick = "fun();" /> </form> </body> </html>
输出
Click the following button to see the effect
Example2
这是使用
prompt()方法的另一个示例。
<!DOCTYPE html> <html> <head> <title> JavaScript prompt() method </title> <script> function fun() { var a = prompt("Enter some text", "the lidihuo.com"); if (a != null) { document.getElementById("para").innerHTML = "Welcome to " + a; } } </script> </head> <body style = "text-align: center;"> <p style = "color: red;"> Hello World </p> <p> Example of the JavaScript prompt() method </p> <button onclick = "fun()"> Click me </button> <p id = "para"></p> </body> </html>
<html> <head> <script type = "text/javascript"> function fun() { prompt(" Hello World \n Welcome to the lidihuo.com \n This is a prompt box "); } </script> </head> <body> <p> Click the following button to see the effect </p> <form> <input type = "button" value = "Click me" onclick = "fun();" /> </form> </body> </html>