防止按Delete和Backspace键 [英] To prevent pressing of Delete and backspace keys

查看:104
本文介绍了防止按Delete和Backspace键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在网络表单中有一个文本框,在单击事件时会打开一个弹出窗口.我想防止用户键入任何东西,也禁止使用Delete和Backspace按钮.我已经阻止键入除Delete和Backspace之外的其他键.如何防止按下Delete和Backspace键?

Hi All,

I''ve a textbox in my web form which opens a popup at click event. I want to prevent users to type any thing and also from using delete and backspace button. I''ve blocked typing other keys except Delete and backspace. How Can I prevent keypressing of Delete and Backspace?

推荐答案

尝试一下-

onkeydown="return isNumberKey(event,this)"

Try this -

onkeydown="return isNumberKey(event,this)"

function isNumberKey(evt, obj)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode == 8 || charCode == 46) return false;
    return true;
}


您可以为文本框添加以下Java脚本功能
You can add following java script function for your text box
function onkeyup(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    if (keycode == 8 || keycode == 46)
        return false;
}


如果要阻止所有输入到文本区域,可以在HTML中设置readonly属性.

如果只想在弹出窗口期间将其禁用,则在弹出窗口的开头将textarea元素的readOnly成员设置为true,然后将其重置为false.
If you want to prevent all input to the textarea, you can set the readonly attribute in the HTML.

If you only want to disable it during the popup, set the textarea element''s readOnly member to true at the start of the popup, and reset it to false afterwards.


这篇关于防止按Delete和Backspace键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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