防止按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.