Firefox为事件对象提供错误

1 javascript firefox jquery event-handling

此代码在chrome上运行良好,但不适用于IE或Firefox.

$('.modal').on("click", ".action", function() {
    if($(event.target).hasClass('added')) {
        if($(event.target).hasClass('remove_vehicle')) {
           //code
        }
Run Code Online (Sandbox Code Playgroud)

我在Firefox控制台上收到此错误:

ReferenceError: event is not defined
[Break On This Error]   

if($(event.target).hasClass('added')) {
Run Code Online (Sandbox Code Playgroud)

这有什么不对?双方event.triggerhasClass都应该在Firefox上运行.

Moh*_*dil 8

试试这个 -

$('.modal').on("click", ".action", function(event) { // see the difference in this line 
    if($(event.target).hasClass('added')) {
        if($(event.target).hasClass('remove_vehicle')) {
           //code
        }
Run Code Online (Sandbox Code Playgroud)