javascript 当用户单击按钮时,如何弹出 textarea?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7759132/
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
How can I have a textarea popup when the user clicks a button?
提问by Briz
I've tried PopBoxto have a textarea pop up, but the functionality of PopBox seems to be incompatible with the game system. (For example, I know for a fact that alert();
and prompt();
works in the html page testing, but does not happen at all in the actual game)
我试过用PopBox弹出一个 textarea,但是 PopBox 的功能似乎与游戏系统不兼容。(例如,我知道一个事实,alert();
并且prompt();
在 html 页面测试中有效,但在实际游戏中根本不会发生)
Currently the game has this confirm boxsystem implemented. Is there a way to add a textarea to this?
目前游戏已经实现了这个确认框系统。有没有办法为此添加一个textarea?
If not, is there any other Jquery/JS tricks/plugins that will allow a textarea box to pop up when a button is clicked?
如果没有,是否有任何其他 Jquery/JS 技巧/插件可以在单击按钮时弹出文本框?
采纳答案by Ricardo Binns
check this plugin
检查这个插件
very easy and clean to use, you can do whatever you want.
使用起来非常简单和干净,你可以做任何你想做的事。
its easy to change the input by a textarea
很容易通过 textarea 更改输入
in jquery.alerts.js
file, search for 'prompt'
case, and change the input
by textarea
.
在jquery.alerts.js
文件中,搜索'prompt'
case,然后更改input
by textarea
。
i made this for me and have been working so far.
我为我做了这个,到目前为止一直在工作。
回答by TheCarver
I'm no expert but I think this is possible:
我不是专家,但我认为这是可能的:
<div id="textAreaDiv" style="visibility:hidden;"><textarea></textarea></div>
<input type="button" onClick="showTextArea()">
<input type="button" onClick="hideTextArea()">
<script>
function showTextArea() {
document.getElementById('textAreaDiv').style.visibility="visible";
}
function hideTextArea() {
document.getElementById('textAreaDiv').style.visibility="hidden";
}
</script>
OR...
或者...
To toggle the DIV with one button, you could do this:
要一键切换 DIV,您可以这样做:
<script>
function showHideTextarea() {
if (document.getElementById('textAreaDiv').style.visibility="hidden")
{
document.getElementById('textAreaDiv').style.visibility="visible";
}
else
{
document.getElementById('textAreaDiv').style.visibility="hidden";
}
}
</script>
And this doesn't need the JQuery library to use.
这不需要使用 JQuery 库。
Hope it helps...
希望能帮助到你...
回答by nschomer
You can have a on the page, which inserts a textarea box when the button is clicked, something like this...
您可以在页面上有一个,它会在单击按钮时插入一个 textarea 框,就像这样......
In original HTML page, stick a blank area, maybe reserving space like so
在原始 HTML 页面中,粘贴一个空白区域,可能像这样保留空间
<div id="Input_Area">
<br>
<br>
</div>
Then, put an onClick event on your button which replaces the innerHTML with your textarea (or create a function that does it, and call it with your onClick event).
然后,在您的按钮上放置一个 onClick 事件,用您的 textarea 替换innerHTML(或创建一个执行此操作的函数,并使用您的 onClick 事件调用它)。
回答by Keith.Abramo
you can try jquery dialog http://jqueryui.it/demos/dialog.
您可以尝试 jquery 对话框http://jqueryui.it/demos/dialog。
This pops open an overlay and a dialog. You can customize this display and interaction to your hearts desire.
这会弹出一个叠加层和一个对话框。您可以根据自己的喜好自定义此显示和交互。