Javascript阻塞退格

Javascript阻塞退格,javascript,backspace,Javascript,Backspace,在这种典型的情况下,我遇到了一个问题,那就是阻止返回导航的退格。但我认为有一点不同 这是我聚焦对象的onKeyDown功能。(当然有一些变化) 上面的函数运行正常,但下面的函数运行不正常 function(key) // Key is the pressed key code { wnd.onKeyDown(key); return key != 8; }; wnd是一个对象及其onKeyDown功能: this.onKeyDown = function(key) {

在这种典型的情况下,我遇到了一个问题,那就是阻止返回导航的退格。但我认为有一点不同

这是我聚焦对象的
onKeyDown
功能。(当然有一些变化)

上面的函数运行正常,但下面的函数运行不正常

function(key) // Key is the pressed key code
{
    wnd.onKeyDown(key);
return key != 8;        
};
wnd
是一个对象及其
onKeyDown
功能:

this.onKeyDown = function(key)
{
    if (key == 37)
        this.charInd = Math.max(0, this.charInd-1);
    else if (key == 39)
        this.charInd = Math.min(this.string.length-1, this.charInd+1);
    else if (key == 8)
    {
        this.string.splice(this.string.length-1, 1);
        this.charInd--;
    }
};

不仅在聚焦对象的
onKeyDown
功能中发送
true
false
以防止导航很重要吗?

您的问题确实不清楚。我知道您试图阻止backspace键导致导航,但是
wnd.onKeyDown
函数定义在哪里?您是否将其与
window.onkeydown
混淆?可能是某种原因导致执行在到达
返回键之前死亡!=8
行。可能
wnd
wnd.string
未定义?这将导致异常并阻止脚本正常工作。
this.onKeyDown = function(key)
{
    if (key == 37)
        this.charInd = Math.max(0, this.charInd-1);
    else if (key == 39)
        this.charInd = Math.min(this.string.length-1, this.charInd+1);
    else if (key == 8)
    {
        this.string.splice(this.string.length-1, 1);
        this.charInd--;
    }
};