最新下载
热门教程
- 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,""); } } } }); }); | |
相关文章
- 星流ai网页版-登录入口一键直达官网体验_星流agent-星流ai最新网址速查 03-01
- 羞羞漫画-免费在线漫画阅读版 03-01
- z-library官网中文版-zlibrary电子书官方站 03-01
- 差差漫画-免费登录畅读 03-01
- jm漫画-网页版最新入口2026 03-01
- picacg漫画网页入口-哔咔漫画官网|二次元在线畅读 03-01