代码改变世界

js事件传入数据(event对象)

2014-05-14 10:40  南言北兼  阅读(1907)  评论(0编辑  收藏  举报

Example: 向事件中传入任意的数据:

1
2
3
4
5
$("p").click( function (event, a, b) {
// when a normal click fires, a and b are undefined
// for a trigger like below a refers to "foo" and b refers to "bar"
 
} ).trigger("click", ["foo", "bar"]);

Example: 通过 event 对象,向事件中传入任意的数据:span>

1
2
3
4
var event = jQuery.Event("logged");
event.user = "foo";
event.pass = "bar";
$("body").trigger(event);

Example: 另外一种通过 event 对象传入数据的方法:

1
2
3
4
5
6
$("body").trigger({
type:"logged",
user:"foo",
pass:"bar"
 
});