惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
爱范儿
爱范儿
Attack and Defense Labs
Attack and Defense Labs
量子位
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
S
Schneier on Security
C
Cisco Blogs
B
Blog RSS Feed
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
Y
Y Combinator Blog
Latest news
Latest news
T
Tailwind CSS Blog
Jina AI
Jina AI
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
P
Palo Alto Networks Blog
V
V2EX
博客园_首页
D
Docker
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
月光博客
月光博客
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Know Your Adversary
Know Your Adversary
L
LangChain Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
The Register - Security
The Register - Security
NISL@THU
NISL@THU

博客园 - 嚣张的沉默

读写txt文档 计算TextBox输入的字数 我常用的正则与SQL语句 DataSet导入到Excel 年月日联动的JS代码 用户控件的传值方法 Repeater模板列 asp.net的几个小技巧 百叶窗效果 建站安全 倒计时代码 解决SQL2000安装服务器挂起 删除.NET的最近项目 屏幕右下角弹出广告 DataSet写入、导出XML 上传图片重命名并创建文件夹 自动跳转页面带参数 微软出的AJAX控件的安装(转载) 第一次开博
限制TextBox输入字数
嚣张的沉默 · 2008-03-05 · via 博客园 - 嚣张的沉默

TextBox有一个TextMode,把它设置成MultiLine后,MaxLength就不好用了.使用这个方法便可以解决此问题
新建一个txt文档,把以下代码复制进去,然后把扩展名改为:.htc后保存.

<PUBLIC:PROPERTY name="charsize" /
<PUBLIC:ATTACH event="onkeypress" handler="doKeyPress" /
<PUBLIC:ATTACH event="onbeforepaste" handler="doBeforePaste" /
<PUBLIC:ATTACH event="onpaste" handler="doPaste" /

<SCRIPT language="JavaScript"> 
// Keep user from entering more than maxLength characters 
function doKeyPress()

    
if(!isNaN(charsize))
    

        maxLength 
= parseInt(charsize); 
        
var oTR = element.document.selection.createRange(); 
        
// Allow user to type character if at least one character is selected 
        if (oTR.text.length >= 1
            event.returnValue 
= true
        
else if (value.length > maxLength-1
            event.returnValue 
= false
    }

}
 
// Cancel default behavior 
function doBeforePaste()

    
if (!isNaN(charsize)) 
    event.returnValue 
= false
}
 
// Cancel default behavior and create a new paste routine 
function doPaste()

    
if (!isNaN(charsize))
    
{
        event.returnValue 
= false
        maxLength 
= parseInt(charsize); 
        
var oTR = element.document.selection.createRange(); 
        
var iInsertLength = maxLength - value.length + oTR.text.length; 
        
var sData = window.clipboardData.getData("Text").substr(0,iInsertLength); 
        oTR.text 
= sData; 
    }
 
}
 
</SCRIPT> 

<asp:textbox id="txtContent" runat="server" CssClass="longform" MaxLength="200" TextMode="MultiLine" Rows="3" style="BEHAVIOR: url('MaxLength.htc'); WORD-BREAK: break-all" charsize="200"> </asp:textbox>

这个 charsize="200" 就是要控制的长度