第一步
以下是核心代碼
在頁面引用或進行封裝都可
<script language=
javascript
type=
text/javascript
>
function textLimitCheck(thisArea
maxLength
SpanId)
{
if (thisArea
value
length > maxLength)
{
thisArea
value = thisArea
value
substring(
maxLength)
thisArea
focus()
}
/*回寫span的值
當前填寫文字*/
var varss=
(剩余字數
+(maxLength
thisArea
value
length)+
)
;
document
getElementById(SpanId)
innerHTML =varss;
}
</script>
第二步
文本框應用此函數
<asp:TextBox ID=
txtOwner_Name
runat=
server
Width=
px
MaxLength=
onkeyup=
textLimitCheck(this
spOwner_Name
)
BackColor=
Info
></asp:TextBox>
<span id=
spOwner_Name
><em>(
字以內)</em></span>
From:http://tw.wingwit.com/Article/program/net/201311/13129.html