如何停止在按退格键上删除一个字母=>专注于文本框 [英] how to stop to erase one letter on press backspace => focus on textbox

查看:60
本文介绍了如何停止在按退格键上删除一个字母=>专注于文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为退格事件编写脚本

如果我按退格键然后专注于文本框

但是一个问题就是它专注于文本框并且它会删除一个字母

,我想专注于没有删除文本框值..

请按下退格键给我关注焦点,没有删除文本框任何字母



i wrote script for backspace event
that if i press backspace then focus on textbox
but one problem that it focus on textbox and it erase one letter
and i want to focus with no erase textbox value..
please give me slution for focus with press on backspace and no erase textbox any letter

if(e.which==8)
{
      $("#txtsid").focus()
}

推荐答案

#txtsid)。focus()
}
("#txtsid").focus() }


原因是BACKSPACE也有默认行为 - 删除一个字符...

如果你想停止默认行为,你必须停止事件的冒泡(传播)......

当你使用jQuery时你可以受益 event.stopPropagation() [ ^ ]

The reason is that BACKSPACE has its default behavior too - deleting one character...
If you want to stop the default behavior you have to stop the bubbling (propagation) of the event...
As you use jQuery you can benefit from event.stopPropagation()[^]
if(e.which==8)
{


#txtsid)。focus()

e.stopPropagation();
}
("#txtsid").focus() e.stopPropagation(); }


这篇关于如何停止在按退格键上删除一个字母=>专注于文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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