用JavaScript限制textarea输入长度 (For: IE、Firefox ...)
<!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" lang="gb2312"> <head> <head> <title> Code:用JavaScript限制textarea输入长度 (For: IE、Firefox ...)</title> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <meta name="author" content="枫岩,[email protected]"> <meta name="keywords" content="textarea,输入长度" /> <meta name="description" content="用JavaScript限制textarea输入长度 (For: IE、Firefox ...)" /> <style type="text/css" media="all"> body {font-size:14px;} </style> </head> <body> maxlength=10 <textarea maxlength="10" onkeyup="return isMaxLen(this)"></textarea> maxlength=20 <textarea maxlength="20" onkeyup="return isMaxLen(this)"></textarea> <script type="text/javascript"> function isMaxLen(o){ var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):""; if(o.getAttribute && o.value.length>nMaxLen){ o.value=o.value.substring(0,nMaxLen) } } </script> </body> </html>
相关推荐
zengni 2020-04-16
Vipwxs 2018-12-19
javaer 2008-09-02
jscjxysx 2019-07-01
冯二爷 2019-07-01
Donutsapps 2019-06-29
无情 2018-12-19
87281248 2017-09-28
原為簡單 2017-09-28
web开发 2017-01-16
勤能补拙孰能生巧 2019-06-28
wndong 2015-12-14
shishaoe 2015-04-10
csstpeixun 2015-04-02
realitycss 2014-05-05
DreamLee 2013-12-13
切慕溪水 2013-07-11
lkj0 2013-05-24