window.prompt 多行输入 JavaScript CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16061005/
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-10-27 03:07:02  来源:igfitidea点击:

window.prompt multiple line input JavaScript CSS

javascriptjqueryhtmlcss

提问by htrufan

I am trying to find a way to make something equivalent to window.prompt, but which allows multiple lines of input.

我试图找到一种方法来制作与 等价的东西window.prompt,但它允许多行输入。

I could create my own using a div with z-indexcontaining a textArea, but I am hoping there is something out there in jQuery or a plugin that would be more elegant.

我可以使用z-index包含 a的 div 创建自己的 div textArea,但我希望 jQuery 或插件中有一些更优雅的东西。

Any ideas?

有任何想法吗?

回答by mattytommo

You can use the jQuery Dialogto do that.

您可以使用jQuery Dialog来做到这一点。

Here's an example: http://jsfiddle.net/RBKaZ/

这是一个例子:http: //jsfiddle.net/RBKaZ/

Using this HTML

使用这个 HTML

<div id="dialog">
    <p>Please enter your name</p>
    <textarea id="name"></textarea>
</div>
<label>Name entered: </label>
<label id="nameentered"></label>
<br />
<input type="button" id="open" value="Open Dialog" />

And this jQuery:

而这个 jQuery:

$("#dialog").dialog({
    autoOpen: false,
    buttons: { 
        Ok: function() {
            $("#nameentered").text($("#name").val());
            $(this).dialog("close");
        },
        Cancel: function () {
            $(this).dialog("close");
        }
    }
});

$("#open").click(function () {
    $("#dialog").dialog("open");
});