简体   繁体   中英

Getting a value from alert box

I'm having a problem extracting a value from an alert box. Is there a way to get a value from a predefined alert box, and if so, how do I do it?

You should probably consider using prompt instead of alert . JavaScript has 3 types of user dialogs: alert , confirm , and prompt .

Using prompt you can get text input from the user. Have a look at the documentation on Window.prompt .

As an example, consider the various usages in the code below:

 var name = prompt("prompt - Please enter your name") alert("alert - Hello, " + name + "! You can't enter text here!"); var clickedOk = confirm("confirm - Do you understand now?"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM