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.trigger并hasClass都应该在Firefox上运行.
试试这个 -
$('.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)