//trigger $('#foo').on('click', function() { alert($(this).text()); }); $('#foo').trigger('click'); $('#foo').on('custom', function(event, param1, param2) { alert(param1 + " " + param2); }); $('#foo').trigger('custom', ['Custom', 'Event']);
var data = { id: 5, name: "张三" }; var events = { "mouseenter": function(event){ $(this).html( "你好," + event.data.name + "!"); }, "mouseleave": function(event){ $(this).html( "再见!"); } }; //为n5绑定mouseenter mouseleave两个事件,并为其传入附加数据data $("body").on(events, "#n5", data);