<body><SCRIPT LANGUAGE="JavaScript">
document.onkeydown = function(e)
{
  e = window.event||e;
  var code = e.keyCode || e.which;
  alert(code);
}
</SCRIPT>

解决方案 »

  1.   

    改称event.which试一下!<script type="text/javascript">
    function insertTab(event,obj) {
    var tabKeyCode = 9;
    if (event.which) // mozilla
    var keycode = event.which;
    else // ie
    var keycode = event.keyCode;
    if (keycode == tabKeyCode) {
    if (event.type == "keydown") {
    if (obj.setSelectionRange) {
    // mozilla
    var s = obj.selectionStart;
    var e = obj.selectionEnd;
    obj.value = obj.value.substring(0, s) + 
    "\t" + obj.value.substr(e);
    obj.setSelectionRange(s + 1, s + 1);
    obj.focus();
    } else if (obj.createTextRange) {
    // ie
    document.selection.createRange().text="\t"
    obj.onblur = function() { this.focus(); this.onblur = null; };
    } else {
    // unsupported browsers
    }
    }
    if (event.returnValue) // ie ?
    event.returnValue = false;
    if (event.preventDefault) // dom
    event.preventDefault();
    return false; // should work in all browsers
    }
    return true;
    }//-->
    </script>
    <textarea onkeydown="return insertTab(event,this);" 
      onkeyup="return insertTab(event,this);" 
      onkeypress="return insertTab(event,this);" 
      rows="30" cols="80" ID=Textarea1>
    </textarea>
      

  2.   

    同志们,请仔细看我的代码,evt.keyCode=9;这句是完成tab键的功能,
    focus到迫不得已才考虑,event.which早就考虑过了。
      

  3.   

    知道阿,为啥不用focus?天知道ff中keyCode是只读的不是!