在这种阻止Backspace导航返回的经典情况下,我遇到了麻烦。但我认为有区别。
这是我聚焦对象的onKeyDown
功能。(当然有一些变化)
function(key) // Key is the pressed key code
{
return key != 8;
};
上面的函数可以正常运行,但是下面的不能。
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--;
}
};
不仅重要的是发送true
或false
聚焦对象的onKeyDown
功能以防止导航?