如何在编写时自动扩展文本区域
如何在书写时自动扩展文本区域?
这是我的代码:
<script type="text/javascript">
function clearContents(element) {
element.value = '';
}
function updateContents(element) {
element.value = "What's on your mind?";
}
</script>
<h1>New status</h1>
<form action="index.php" method="post" name="new_message">
<textarea id="message" onFocus="clearContents(this);" onKeyPress="catchEnter(this);">What's on your mind?</textarea>
<input type="button" value="Post">
</form>
How can I auto expand my text area as I write?
This is my code:
<script type="text/javascript">
function clearContents(element) {
element.value = '';
}
function updateContents(element) {
element.value = "What's on your mind?";
}
</script>
<h1>New status</h1>
<form action="index.php" method="post" name="new_message">
<textarea id="message" onFocus="clearContents(this);" onKeyPress="catchEnter(this);">What's on your mind?</textarea>
<input type="button" value="Post">
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我一直在使用 Unwrongest 的弹性文本框,它是一个非常棒的插件。
只需包含该插件,然后使用以下命令调用该插件即可:
就是这样。
在此处查看演示:http://jsfiddle.net/janjarfalk/r3Ekw/
how to achieve this in 3 steps:
第 1 步:将其添加到 html 中的
中:
第 2 步:将其添加到 html 文件中的
标记:
第 3 步:仅当第 2 步后不起作用时才使用此步骤。在第 1 步的代码上方添加下一行:
您已完成。如果您已经有 jQuery,请跳过步骤 3。
I have been using the elastic textbox from Unwrongest and it's a fantastic plugin.
Just include the plugin, and then call the plugin with just this:
that's it.
Check out a demo here: http://jsfiddle.net/janjarfalk/r3Ekw/
how to achieve this in 3 steps:
step 1: Add this to your
<head>
in your html:step 2: Add this to your html file, just before
</body>
tag:step 3: use this step ONLY if it doesn't work after step 2. Add the next line above your code from step 1:
You are done. If you already have jQuery, skip step 3.
然后巴姆!!!你有一个不断增长的文本区域。您可能需要考虑边框和填充。将那些包含在函数中。
Then Bam!!! you have a growing textarea. You may have to account for borders and padding. include those in the function.