最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jQuery实现限制文本框的输入长度
时间:2022-06-25 17:22:15 编辑:袖梨 来源:一聚教程网
jQuery限制文本框输入,包含粘贴。
| 代码如下 | 复制代码 |
//限制文本框的输入长度 $(function() { $(document).on("keypress",".txt-valid-len",function(e) { if(e.keyCode == 8) { returntrue; } else{ varlen = $(this).data("maxlength") || 0; if(len > 0) { return(this.value.length <= len); } } returntrue; }); //粘贴 $(document).on("paste",".txt-valid-len",function() { varlen = $(this).data("maxlength") || 0; if(len > 0) { return((this.value.length + event.clipboardData.getData('Text').length) <= len); } returntrue; }); $(document).on("keyup input",".txt-valid-len",function(e) { varkeyCode = e.keyCode || e.which || e.charCode; if(keyCode == 46 || keyCode == 8) { } else{ varlen = $(this).data("maxlength") || 0; if(len > 0) { if(this.value.length > len) { this.value = com.cutStr(this.value, len,""); } } } }); }); | |
相关文章
- 抖音搜索不到热门视频怎么办 03-25
- z-lib软件-超全电子书库特点 03-25
- 重庆公交卡余额怎么查询 03-25
- 驱动人生系统必备组件修复不了解决方法 03-25
- 在浙学电脑版登录地址-在浙学官网网页版登录入口 03-25
- 微博官网网页版入口-微博热搜榜实时查询链接地址 03-25