使用jquery的改写模式 [英] Overtype mode with jquery

查看:75
本文介绍了使用jquery的改写模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让我的输入字段表现得好像键盘处于改写模式一样?

How could I make my input field act as if the keyboard is in overtype mode?

我尝试使用键码中的删除按钮触发按键事件用户输入一个值但没有任何反应。

I tried to trigger the keypress event with the delete button in keycode when the user enter a value but nothing happen.

推荐答案

类似于:

<input onkeydown="this.oldSize = this.value.length;" 
  onkeypress="var n = this; setTimeout(function() {
      if(n.value.length > n.oldSize) {
        var s = n.selectionStart;
        n.value = n.value.substr(0, s) + n.value.substr(s + 1);
        n.selectionStart = n.selectionEnd = s;
      }
    },10);">

这篇关于使用jquery的改写模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆