我想访问以下标记中的 data-global-id 值,但由于范围界定,我不确定如何执行此操作。
例如:
<div data-global-id="168" class="remove-as-favorite">remove as favorite</div>
$('.remove-as-favorite').on('click',function(){
var global_id=$(this).data('global-id');
// this works
alert('here i am in something: ' + global_id);
// this doesn't work
event_handler.remove_as_favorite();
});
// want to access the data-global-id value in here; how to get access to this?
event_handler={
remove_as_favorite: function(){
// how to get access to this here; assuming this refers to event_handler
var global_id=$(this).data('global-id');
alert("here i am global_id:" + global_id);
}
}
谢谢
** 编辑 1 **