跪求jquery中的bind()参数中function参数问题

2025-05-01 16:26:10
推荐回答(2个)
回答1:

function是自定义函数,event应该是事件,data就就是数据,这些都是用程序员自己完成的。

查看一下jquery中bind()的api:
http://api.jquery.com/bind/

The Event object
The handler callback function can also take parameters. When the function is called, the event object will be passed to the first parameter.
The event object is often unnecessary and the parameter omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered. However, at times it becomes necessary to gather more information about the user's environment at the time the event was initiated. View the full Event Object.
Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object.
Using the event object in a handler looks like this:
$(document).ready(function() {

$('#foo').bind('click', function(event) {
alert('The mouse cursor is at ('
+ event.pageX + ', ' + event.pageY + ')');
});
});

Note the parameter added to the anonymous function. This code will cause a click on the element with ID foo to report the page coordinates of the mouse cursor at the time of the click.

回答2:

如果你这里面写的是绑定click方法,我就不知道怎么回事儿了,但如果不是click,而是chick,那就有可能知道data是什么,如下是API中的DEMO:

Has an attached custom event.








可以看出,这里绑定的是myCustomEvent,myCustomEvent又是在click的时候用rigger进行绑定的,所以,后面可以传一个参数。

因此,我觉得你想要的data应该是这样来的。

至于event我就不用解释了,你应该知道的...