Javascript 带有表单和一个输入文本的警报框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14808312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alert Box with form and one input text
提问by Ofir Attia
I want to open an alert box (Javascript) with one input text, then on user click is submit to another page, its like a form with one input text, all the examples that given are modals examples, i just need an alertbox.
我想用一个输入文本打开一个警报框(Javascript),然后在用户单击时提交到另一个页面,它就像一个带有一个输入文本的表单,给出的所有示例都是模态示例,我只需要一个警报框。
回答by James Allardice
回答by Meherzad
You can use prompt for getting user input
您可以使用提示获取用户输入
var retVal = prompt("Enter your name : ", "your name here");
document.getElementById(formId).submit();
this variable you can access and redirect accordingly
您可以相应地访问和重定向此变量
You can store the value of prompt in any control within the form which you can access on the submitted page after the page is submitted.
您可以将 prompt 的值存储在表单中的任何控件中,您可以在提交页面后在提交的页面上访问该控件。
fiddle http://jsfiddle.net/ze3rX/
回答by ramo
You can do a prompt
你可以做一个提示
name = prompt('Please enter your name');
and then
进而
window.location = "http://yourdomain.com/yourscript.php?name="+name;
Now what you're doing is sending the name that the user enters to your script using the GET method.
现在您要做的是使用 GET 方法将用户输入的名称发送到您的脚本中。
You will obviously have to do a bit of validation and sanitization, but that's how GET basically works. If you want to POST the data entered, then look into AJAX (XmlHttpRequests)and send the variables/params to the script URL of your choice.
显然,您必须进行一些验证和清理,但这就是 GET 的基本工作方式。如果要发布输入的数据,请查看AJAX (XmlHttpRequests)并将变量/参数发送到您选择的脚本 URL。

