怎么算没有。人物进入了多行文本框,直到140个字符 [英] How to count no. of characters entered in multiline textbox till 140 characters

查看:150
本文介绍了怎么算没有。人物进入了多行文本框,直到140个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何算没有。在多行文本框输入的字符,我想用我的多行文本框中输入最多140个字符vb.net ...

总之我想文本框输入限制只有140个字符....

我忒以下code做....但我想实现140个字符的多行TextBox的限制:

 <脚本类型=文/ JavaScript的>
        功能计数(X){           的document.getElementById(Label1的)的innerHTML =的document.getElementById(TextBox2中)value.length。;
        }
< / SCRIPT>
< ASP:文本框ID =TextBox2中=服务器HEIGHT =78px
            的TextMode =多行WIDTH =224px的onkeyup =计数(this.id)
            MAXLENGTH =140>< / ASP:文本框>


解决方案

下面是如何做到这一点的例子。所述函数接受您限制为,控制的(客户端,HTML)id来计数的字符数,和元件,以输出计数的id成

 <脚本类型=文/ JavaScript的>
    功能CountChars(charLimit,inputId,outputId){
        VAR remainingChars = charLimit - 的document.getElementById(inputId).value.length;
        的document.getElementById(outputId).innerHTML = remainingChars;
    }
< / SCRIPT>

和这里的用法示例

 < ASP:文本框ID =TextBox2中WIDTH =100%的TextMode =多行行=10MAXLENGTH =140
        =服务器>< / ASP:文本框>
&所述; / P>
&所述p为H.;
    剩余字符:<跨度ID =characterCount> 140℃; / SPAN>< / P>

挂钩于code中的事件处理程序的背后,在页面加载事件:

 保护小组AddCharCountHandler()
    TextBox2.Attributes.Add(的onkeyup,CountChars(与& 140&放大器;,与& TextBox2.ClientID&放大器;',&放大器;'characterCount');)
结束小组

请注意,我打电话使用txtDescription.ClientId功能,虽然我的输出范围有一个固定的ID。

How to count no. of characters entered in multiline textbox, i wanna enter maximum 140 characters in my multiline textbox using vb.net ...

In short i want textbox to enter limit is only 140 characters ....

i have te following code to do that .... but i wanna implement 140 characters limit in multiline textbox :

<script type="text/javascript">
        function Count(x) {

           document.getElementById("Label1").innerHTML = document.getElementById("TextBox2").value.length;
        }
</script>


<asp:TextBox ID="TextBox2" runat="server" Height="78px" 
            TextMode="MultiLine" Width="224px" onkeyup="Count(this.id)" 
            MaxLength="140"></asp:TextBox>

解决方案

Here's an example of how to do this. The function takes the number of characters you're limiting to, the (client, HTML) id of the control to count, and the id of the element to output the count into

<script type="text/javascript">
    function CountChars(charLimit, inputId, outputId) {
        var remainingChars = charLimit - document.getElementById(inputId).value.length;
        document.getElementById(outputId).innerHTML = remainingChars;
    }   
</script>

And here's a usage example

    <asp:TextBox ID="TextBox2" Width="100%" TextMode="MultiLine" Rows="10" MaxLength="140"
        runat="server"></asp:TextBox>
</p>
<p>
    Characters remaining: <span id="characterCount">140</span></p>

Hook up the event handler in code behind, in the page load event:

Protected Sub AddCharCountHandler()
    TextBox2.Attributes.Add("onkeyup", "CountChars(" & 140 & ", '" & TextBox2.ClientID & "'," & "'characterCount');")
End Sub

Note that I'm calling the function using txtDescription.ClientId, although my output span has a fixed id.

这篇关于怎么算没有。人物进入了多行文本框,直到140个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆