jQuery 显示带有文本字段的警报框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13599236/
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
show alert box with Text field in it
提问by Mr_Green
I am new to jquery. I want to show a Alert Box with TextBox field in it, whenever the page loads. Something like this:
我是 jquery 的新手。我想在页面加载时显示一个带有 TextBox 字段的警报框。像这样的东西:
Enter Your Username: //Title
___________________ //TextBox field (value will be stored in var for later use)
OK //Button
I know
我知道
var username = "username"; //already entered message
alert(username);
How to achieve the above Alert Box? should I manually code it?
Giving an example in jQuery
is preferable. I am trying to do this for my chat application where username is required to show in the chat. I searched alot but couldn't find any useful related to asp.net and jquery.
如何实现上面的Alert Box?我应该手动编码吗?最好
举个例子jQuery
。我正在尝试为我的聊天应用程序执行此操作,其中需要在聊天中显示用户名。我搜索了很多,但找不到任何与 asp.net 和 jquery 相关的有用信息。
回答by Matthew Dean
回答by Michael Jasper
Giving an example in jQuery is preferable.
最好在 jQuery 中给出一个例子。
jQuery Impromptuprovides an aesthetic JavaScript Prompt, which is equally easy to call as JavaScripts window.prompt
method:
jQuery Impromptu提供了一个美观的 JavaScript Prompt,它与 JavaScriptswindow.prompt
方法一样容易调用:
//Simple Prompt
$.prompt('Example 1');
//Opacity of the modal
$.prompt('Example 3',{ opacity: 0.2 });
//Adding Callbacks
function mycallbackfunc(e,v,m,f){
alert('i clicked ' + v);
}
$.prompt('Example 8',{ callback: mycallbackfunc });
回答by Nikko Reyes
You can use JQueryUI Dialogto show a form in a dialog box.
您可以使用JQueryUI Dialog在对话框中显示表单。
回答by bipen
"I want to show a Alert Box with TextBox field in it,". alert box with text field is not possible at all..(from what i have learnt till now).... u can use other jquery plugins like dialog
“我想显示一个带有 TextBox 字段的警报框,”。带有文本字段的警报框根本不可能......(从我学到的到现在)......你可以使用其他 jquery 插件,如对话框
to do the same..
做同样的..
or the classic way using prompt
或使用提示的经典方式
var name=prompt("Please enter your name","Harry Potter");
回答by coder
Try this:
尝试这个:
$(document).ready(function(){
var msg = window.prompt("Write your name", "Name");
alert(msg);
});?