控制 freetextbox 长度的jquery该如何写哇 
ASP 里边写了个
<FTB:FreeTextBox ID="FreeTextBox1" runat="server" Width="550px"></FTB:FreeTextBox>
要如何才能用jquery把他的utf-8格式长度限制在4000个以内并且还能显示还能动态剩下多少个字啊?

解决方案 »

  1. 一: maybe can not support
    <FTB:FreeTextBox ID="txtDescription" runat="Server" AutoGenerateToolbarsFromString="false"
                                            BackColor="White" EnableHtmlMode="false" clientSideTextChanged="FtbSetOnTime(this,500)" Width="770px" Height="150px" BreakMode="LineBreak" />
    function FtbSetOnTime(ftbobj, maxlength) {
                var nLength = ftbobj.document.body.text.length;
                if (nLength > maxlength) {
                    ftbobj.document.body.text.substring(0, maxlength);
                }
            }二: have test it ok
    <FTB:FreeTextBox ID="txtDescription" runat="Server" EnableHtmlMode="false" AutoGenerateToolbarsFromString="false"
                                            BackColor="White" Width="770px"
                                            Height="150px" BreakMode="LineBreak" />
                                        <asp:RegularExpressionValidator ID="revTxtDescription" runat="server"  ControlToValidate="txtDescription" SetFocusOnError="true" ErrorMessage="RegularExpressionValidator"
                                            ValidationExpression="^(\s|\S){0,500}$" ForeColor="Red">The field's maxlength is must less than or equal to 500.</asp:RegularExpressionValidator>
      

  2. jquery or:
     $("input[id$='btHeaderSave'],input[id$='NextToDetail']").live("click", function () {
                    var $obj = $(document.getElementById('MainContent_txtDescription_designEditor').contentWindow.document.body);
                    var flag = 0;
                    var ss = $obj.text();
                    $obj.blur(function () {
                        if ($(this).text().replace(/[ ]/g, "") != "")
                            $("#ftbDesc").hide();
                    });
                    if (ss.replace(/[ ]/g, "") == "") {
                        $("#ftbDesc").show();
                        $("#ftbDesc").text("*The filed is required.");
                        flag = 1;
                    } else {
                        $("#ftbDesc").hide();
                    }
                    if ($("#MainContent_drpCallingEntity_txtEdit").val().toLowerCase() != $("#MainContent_drpCallingEntity_ddlSelect").find("option:selected").text().toLowerCase()) {
                        flag = 1;
                        $("#callspan").show();
                    } else { $("#callspan").hide(); }
                    if (flag == 1)
                        return false;
                })
      

类似问题 »