实现文本框中输入限制字数的效果:
<!DOCTYPE html> <html> <head lang="zh"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta charset="utf-8" /> <title>采销商品基本信息</title> </head> <body> <input type="text" id="username" name=""> <div>您还可以写<span id="result">10</span>/10个字</div> <script type="text/javascript" src="./../js/jquery.js"></script> <script type="text/javascript"> $("#username").bind(‘input‘,function(){ var bb=$(‘#username‘).val();// var cc=bb.substring(0,10);// $(‘#username‘).val(cc);//该三行写在“input”函数外面也可以 var aa=$(this).val().length; if(aa<10){ $(‘#result‘).html(10-$(this).val().length); }else{ $(‘#result‘).html("0"); } }) </script> </body> </html>
实现效果:
时间: 2024-11-10 01:09:28