javascript 有没有办法用两个输入字段创建提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17994208/
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
Is there any way to create prompt with two input fields?
提问by TN888
Is there any way to create prompt in JavaScript with two input fields ?
有没有办法在 JavaScript 中使用两个输入字段创建提示?
I tried that code, but it didn't help me :
我试过那个代码,但它没有帮助我:
var a = prompt("A : ", "");
var b = prompt("B : ", "");
alert(a + "\n" + b);
采纳答案by NDM
This is not possible with an OS or native browser window popping up. You will have to create a custom overlay dialog.
这在弹出的操作系统或本机浏览器窗口中是不可能的。您必须创建一个自定义叠加对话框。
I would advise using a library like jQuery UIto do this. You can then customize whatever is in the popup.
我建议使用像jQuery UI这样的库来做到这一点。然后,您可以自定义弹出窗口中的任何内容。
You can view a demo of the dialog here
回答by Quentin
Short of constructing your own using DOM methods and Input elements: No.
缺少使用 DOM 方法和 Input 元素构建自己的方法:不。
回答by Quentin
JavaScript Code
JavaScript 代码
<script>
$( "#create-user" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
</script>
Html Code:
html代码:
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text">
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text">
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" class="text">
</fieldset>
</form>
</div>
<button id="create-user">Create new user</button>
回答by Luis Dulanto
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>dialogo</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<script>
function abrete(){
$("#dialog" ).dialog();
}
</script>
<div id="dialog" title="Create new user" style="display:none;">
<p class="validateTips">All form fields are required.</p>
<form action='tuscript.php'>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text">
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text">
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" class="text">
</fieldset>
</form>
</div>
<button onclick='abrete()'>Create new user</button>
</body>
</html>