jQuery动态计算文本框内的可输入字数
<!doctype html> <html> <head> <meta charset="utf-8"> <title>jQuery动态计算文本框内的可输入字数</title> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/textSum.min.js"></script> <style type="text/css"> *{ box-sizing:border-box;} body{ background:#f4f4f4;} span{ font-size:12px;} p{ margin:5px 0;} .textWrap{ margin:10px 0 20px;} .textWrap input,.textWrap textarea{ display:inline-block; background:#fff; border-radius:4px; border:1px solid #ddd; height:34px; width:100%; padding:7px 12px; padding-right:80px; line-height:20px; font-size:14px; color:#333;} .textWrap textarea{ height:80px;} </style> </head> <body> <br> <div style="margin:50px auto; width:60%;"> <p><span>input maxlength = 10</span></p> <div class="textWrap wordSumTotal"> <input type="text" name="" maxlength="10"> </div> <p><span>input maxlength = 20</span></p> <div class="textWrap wordSumTotal"> <input type="text" name="" style="height:46px;" maxlength="20"> </div> <p><span>input maxlength 缺省时,默认maxlength = 10</span></p> <div class="textWrap wordSumTotal"> <input type="text" name=""> </div> <p><span>textarea maxlength = 20</span></p> <div class="textWrap wordSumTotal"> <textarea name="" cols="" rows="" maxlength="200"></textarea> </div> <br> <p>使用方法:</p> <p><pre><code>$('class or element').textSum();</code></pre></p> </div> <script type="text/javascript"> $(function(){ $('.wordSumTotal').textSum(); }); </script> </body> </html>
相关推荐
89510194 2020-06-27
张荣珍 2020-11-12
goawalk 2020-10-29
ahailanjianj 2020-10-10
clong 2020-08-23
hell0kitty 2020-07-28
leodengzx 2020-07-04
JayFighting 2020-06-28
小灯光环 2020-06-11
yunsaiqing 2020-06-06
弱思 2020-06-04
mysteryrat 2020-06-02
liqinglin0 2020-06-01
jvm 2020-05-30
curiousL 2020-05-27