最新下载
热门教程
- 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,""); } } } }); }); |
相关文章
- 碧蓝航线大型作战装备研发优先级攻略 04-30
- 我的勇者游侠怎么搭配最强 04-30
- 仙剑世界照影迷妄镜任务流程完整解析 04-30
- CF手游王者风神保底价格攻略 04-30
- 明日之后前期装备推荐依据分享 04-30
- 明日之后菊花瓣食谱怎样 04-30