您可能能够捕获onKeyDown事件。如果键码等于tab键,则用3个空格或类似的替换选项卡。
更新:
我在firefox 3中对此进行了测试。允许您键入选项卡而不会失去焦点。请注意b/c此代码只会在文本框的末尾附加制表符。因此,如果用户在文本中间键入选项卡,则选项卡仍将显示在末尾。
function kH(e)
{
//capture key events
var pK = document.all? window.event.keyCode:e.which;
//if target is textbox and key is tab
if(e.target.type=='text' && pK==0)
{
//append tab to end of target value
e.target.value = e.target.value + "\t";
//Cancel key event
return false;
}
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);