jquery .on()双击传递数据

时间:2013-03-29 00:37:24

标签: jquery javascript-events event-handling

使用时

$(document).on('dblclick', '#selector_id', {form_key:10}, my_function)

my_function = function(){
    console.log(event)
}

根据the documentation

,我希望能够从form_key检索event.data

但是,在这种情况下,我得到的是MouseEvent,而不是Event,而且它没有data属性。

我错过了什么?

1 个答案:

答案 0 :(得分:8)

添加您尝试使用的参数,它可能有效:

$(document).on('dblclick', '#selector_id', {form_key:10}, my_function)

function my_function(event){ // <- event
    console.log(event)
}

并记住传递的数据在event.data中可用,例如:

event.data.form_key

FIDDLE