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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:59:09  来源:igfitidea点击:

Alert Box with form and one input text

javascript

提问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

Assuming I've understood your question correctly, you can use the DOM promptmethod:

假设我已经正确理解了您的问题,您可以使用 DOMprompt方法:

var result = prompt("Enter a value");

回答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/

小提琴 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。

回答by NetStarter

You can check it on your own here is a link where you can have a look at different types of pop up box using javascript popup box

您可以自己检查这里是一个链接,您可以在其中使用 javascript弹出框查看不同类型的弹出