Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取错误“;ReferenceError:未定义事件";_Javascript_Jquery_Firebug_Keypress - Fatal编程技术网

Javascript 获取错误“;ReferenceError:未定义事件";

Javascript 获取错误“;ReferenceError:未定义事件";,javascript,jquery,firebug,keypress,Javascript,Jquery,Firebug,Keypress,在项目上存在下一个js函数 function LoginKeyPressCheck() { $('#txtusername, #txtpassword').keypress(function (evt) { var charCode = (evt.which) ? evt.which : event.keyCode; // here get error $('#Errormsg').html(''); $('#Err_ValidateUser').html('');

在项目上存在下一个js函数

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();
        }
    }
});
当单击按钮
选项卡
获取错误“ReferenceError:未定义事件”时

尝试在FireBug中调试此函数,但从第
var charCode=(evt.which)行开始。
光标在
else
块中移动

我不知道哪里出了问题

谢谢。

更改此行

var charCode = (evt.which) ? evt.which : evt.keyCode;
未定义变量事件,因此无法使用它

var charCode = (evt.which) ? evt.which : event.keyCode;
这应该是

var charCode = (evt.which) ? evt.which : evt.keyCode;

您使用event.keyCode,但从未定义它,它只是代码中的一个输入错误

OMG。。为什么我没有看到这个。谢谢。你是个天才;)(y)