获取错误"ReferenceError:event not defined"

dem*_*emo 2 javascript jquery firebug keypress

项目存在下一个js-function

function LoginKeyPressCheck() {
$('#txtusername, #txtpassword').keypress(function (evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode; // here get error
    $('#Errormsg').html('');
    $('#Err_ValidateUser').html('');
    if (charCode === 13) {
        evt.preventDefault();
        $('#Err_ValidateUser').html('');
        if ($.trim($('#txtusername').val()).length === 0) {
            $('#Err_ValidateUser').html('Validation Error: Value is required');
        }
        else {
            loginProcess();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

单击按钮时TAB出现错误"ReferenceError:event not defined".

尝试在FireBug中调试此函数,但是从行中的行var charCode = (evt.which)...光标移动else.

我无法解决问题所在.

谢谢.

Ale*_* T. 7

改变这一行

var charCode = (evt.which) ? evt.which : evt.keyCode;
Run Code Online (Sandbox Code Playgroud)

变量事件未定义,因此您无法使用它