I have a question that I want to put an input in an alert box. What thing I have to do to create this? To make it I've to put an another tag, attrib, special properities, etc... Thanks. I think could be like this:
<!DOCTYPE html> <html> <head> <title>example</title> </head> <body> <script type="text/javascript"> alert("<input></input>"); </script> </body> </html>
You can use
var resp = window.prompt("Your question")
window.prompt is a blocking method (like alert). The program execution will halt until the user enters a value.
只需使用var value = prompt('Your Question');
This code been executed:
<!DOCTYPE html> <html> <body> <h2>JavaScript Confirm Box</h2> <button onclick="myFunction()">Try it</button> <input id="demo" /> <script> function myFunction() { var txt; if (confirm("Press a button!")) { txt = "You pressed OK!"; } else { txt = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = txt; console.log(txt); } </script> </body> </html>
window object comes with three methods for showing user dialog boxes
this methods will halt current executing program till user provide any response to this box
window.prompt(text, defaultText)
this will take value from user for further process
window.alert(message)
this will only alert user for his action.
window.confirm(message)
this will take user response in boolean form for further process
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.