jquery 文字输入个数限制显示剩余效果代码
代码语言:html
所属分类:表单美化
代码描述:jquery 文字输入个数限制显示剩余效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/bootstrap.3.3.4.css"> </head> <body> <div class="page-header"> <h3 class="text-center">textarea 显示限制输入字符</h3> </div> <form id="testForm" class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">反馈</label> <div class="col-md-6"> <textarea class='form-control' name='test' onkeyup='textAreaChange(this)' onkeydown='textAreaChange(this)' rows='5'></textarea> <div class='text-right'> <em style='color:red'>10</em>/<span>10</span> </div> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-6"> <button type="button" class="btn btn-info" id="testConfirm">确认提交</button> </div> </div> </form> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <script type="text/javascript"> //显示限制输入字符method function textAreaChange(obj) { var $this = $(obj); var count_total = $this.next().children('span').text(); var count_input = $this.next().children('em'); var area_val = $this.val(); if (area_val.len() > count_total) { area_val = autoAddEllipsis(area_val, count_total); //根据字节截图内容 $this.val(area_val); count_input.text(0); //显示可输入数 } else { count_input.text(count_total - area_val.len()); //显示可输入数 } } //得到字符串的字节长度 String.prototype.len = function() { return this.replace(/[^\x00-\xf.........完整代码请登录后点击上方下载按钮下载查看
网友评论0