js控制asp.net服务器端控件textbox设置为多行时输入字符长度

23 篇文章 0 订阅
1 篇文章 0 订阅

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="admin_Clu.aspx.cs" Inherits="admin_admin_Clu" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>企业文化</title>
    <link href="../my.css" rel="Stylesheet" type="text/css" /> 
    <script language="javascript"> 
    <!-- 
        function MaxLength(field,maxlimit)
        { 
             var j = field.value.replace(/[^\x00-\xff]/g,"**").length; 
             //alert(j); 
             var tempString=field.value; 
             var tt=""; 
             if(j > maxlimit)
             { 
                 for(var i=0;i<maxlimit;i++)
                 { 
                    if(tt.replace(/[^\x00-\xff]/g,"**").length < maxlimit) 
                    tt = tempString.substr(0,i+1); 
                    else 
                    break; 
                 } 
                 if(tt.replace(/[^\x00-\xff]/g,"**").length > maxlimit) 
                 tt=tt.substr(0,tt.length-1); 
                 field.value = tt; 
               }
               else
               { 
                     ; 
               } 
         } 
    -->
</script>   
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table align="center" style="width: 682px; height: 303px;" border="0" cellpadding="0"
                cellspacing="0">
                <tr>
                    <td style="width: 615px">
                    </td>
                </tr>
                <tr>
                    <td align="center" style="width: 615px; height: 20px;">
                        <asp:Label ID="Label1" runat="server" Text="企业文化" Width="105px" Font-Names="宋体" Font-Size="12pt"></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 615px; height: 150px;" align="right">
                        <asp:TextBox ID="TextBox1" runat="server" Height="202px" TextMode="MultiLine"  Width="98%"
                            Font-Names="宋体" Font-Size="12pt" onpropertychange="MaxLength(this,1300)"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 615px" align="center">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="企业文化不能为空"
                            ControlToValidate="TextBox1"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td style="width: 615px" align="center">
                        <asp:Button ID="Button2" runat="server" Text="提交" OnClick="Button2_Click" Width="127px" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

其中<tr>
                    <td style="width: 615px; height: 150px;" align="right">
                        <asp:TextBox ID="TextBox1" runat="server" Height="202px" TextMode="MultiLine"  Width="98%"
                            Font-Names="宋体" Font-Size="12pt" onpropertychange="MaxLength(this,1300)"></asp:TextBox></td>
                </tr>中的 onpropertychange="MaxLength(this,1300)1300代表字符个数


http://xiangweiwei1418.blog.hexun.com/6355434_d.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值