facebook - 如何创建一个没有滚动条动态增长的多行文本框?

标签 facebook textbox resize textinput

我需要在我的应用程序中使用文本框(多行)。它需要随着用户输入文本而增长。我希望该文本框在没有任何滚动条的情况下增长。我尝试了 allow=resize:null 但它只是阻止文本框被拉伸(stretch)。我想要的只是一个文本框,正如我们在 facebook 评论/共享区域中看到的那样,它的增长简单,侧面没有任何滚动条。我希望我已经清楚地解释了它。

最佳答案

您可以使用如下内容:(来源:Expandable or Auto-Resize TextBox Height by Colt Kwong)

    <asp:TextBox ID="txtMsg" runat="server"  TextMode="MultiLine" 
style="overflow:hidden" onkeyup="AutoExpand(this, event)" Rows="2" />

使用此 JavaScript:

    function AutoExpand(txtBox, event) 
{
    if (event.keyCode == "13" || event.keyCode == "8") {
        var therows = 0
        var thetext = document.getElementById(txtBox.id).value;
        var newtext = thetext.split("\n");
        therows += newtext.length

        document.getElementById(txtBox.id).rows = therows;
        return false;
    }
}

或者,如果您喜欢 jquery,您应该看看 jQuery autoResize Plugin .

A plugin for jQuery which changes the dimensions of input elements to suit the amount of data entered. It operates on textarea, input[type=text] and input[type=password] elements.

使用方法如下:

$('textarea#foo').autoResize();

您可以传递选项:

$('textarea#foo').autoResize({
    maxHeight: 200,
    minHeight: 100
});

关于facebook - 如何创建一个没有滚动条动态增长的多行文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9943329/

相关文章:

Facebook Feed 对话框参数与开放图元标签

winforms - 仅当文本不适合时,如何才能在 System.Windows.Forms.TextBox 上显示滚动条?

excel - 在文本框中插入日期 - VBA

javascript - jquery javascript 调整抖动大小

android - 找不到 com.parse.bolts :bolts-android:1. 1.2。在手机差距项目(android studio)中?

javascript - 从 Facebook 帖子打开 Chrome/Firefox (Android OS) 的 URL 方案

python - 无法在 Django 站点上配置 Facebook 登录

javascript - 如何根据 JavaScript 中的文本框输入更改数组中的图像?

javascript - 谷歌地图 API 3 和 jQTouch

css - 在 CSS 中隐藏调整大小 handle 图标