最新下载
热门教程
- 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,""); } } } }); }); |
相关文章
- 《异界事务所》光谱项链哪几种 06-30
- 《雾境序列》波比角色大全全解析 06-30
- 《星球重启》SSR宠物盲盒免费怎么获得 06-30
- 操作教程:常见的NFT被盗手段?为什么NFT玩家成为黑客目标? 06-30
- 拳皇97风云再起出招表-拳皇97风云再起技能招式表一览 06-30
- 鸣潮坎特蕾拉培养攻略-鸣潮坎特蕾拉培养材料一览 06-30