简体   繁体   English

在FreeTextBox行中限制字符

[英]Limit Character in FreeTextBox line

I've known many ways to limit the characters inputed inside the Textbox control or Freetextbox control. 我知道许多方法可以限制在Textbox控件或Freetextbox控件内输入的字符。

How can I limit the character in each line (row) of FreeTextBox control??? 如何限制FreeTextBox控件的每一行(行)中的字符???

For example, if the character in a line is 200, then it auto go to the next line 例如,如果一行中的字符为200,则它将自动转到下一行

Best regard! 最良好的问候!

Hello this tricky way to handle by Javascript or JQuery.. Please follow below code for same with Jquery 您好,通过Javascript或JQuery处理这种棘手的方法。.请按照以下代码对Jquery进行处理

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<asp:TextBox ID="txtData" CssClass="text-limit" runat="server" TextMode="MultiLine" style="width:500px; height:150px;"></asp:TextBox> 

<script type="text/javascript">
    var charactorPerLine = 20;
    $(function () {
        $(".text-limit").keydown(function (event) {
            // Allow: backspace(8), delete(46), tab(9), escape(27) and enter(13) 
            if ($.inArray(event.keyCode, [46, 8, 9, 27, 13]) !== -1 ||
            // Allow: Ctrl+A
                (event.keyCode == 65 && event.ctrlKey === true) ||
            // Allow: home, end, left, right
                (event.keyCode >= 35 && event.keyCode <= 39)) {
                // let it happen, don't do anything
                return;
            }
            else {

                if ($(this).val().lastIndexOf("\n") == -1) {
                    if ($(this).val().length >= charactorPerLine) {
                        $(this).val($(this).val() + "\n");
                    }
                }
                else {
                    if (($(this).val().length - $(this).val().lastIndexOf("\n")) >= charactorPerLine {
                        $(this).val($(this).val() + "\n");
                    }
                }

            }
        });
    });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM