无法处理它(需要理解 jQuery 处理程序)

发布于 2024-09-01 12:12:22 字数 355 浏览 3 评论 0原文

我什至都不好意思问,但有人可以帮助我理解什么是“处理程序”。我对 jQuery 很陌生,API 不断有类似以下内容的引用:

toggle( handler(eventObject), handler(eventObject), [ handler(eventObject) ] )

我挠头对自己说“处理程序到底是什么”。然后我检查了我的两本 jquery 书籍,并没有真正看到任何具体内容。我明白事件处理程序的作用,它处理事件。但上述上下文中的“处理程序”一词让我感到困惑,包括“eventObject”。我尝试用 google 搜索它,但无法真正找到与 jquery 相关的处理程序到底是什么的真正清晰的定义。感谢您的帮助=]

I'm embarrassed to even ask BUT could someone help me understand what a "handler" is. I am new to jQuery and the API constantly has references similar to the following:

toggle( handler(eventObject), handler(eventObject), [ handler(eventObject) ] )

I scratch my head and say to myself "what the hell is a handler". Then I check my 2 jquery books and don't really see anything specific there. I get what an event handler does, it handles an event. But the word handler in the above context confuses me including "eventObject". I tried to google it but could not really find a really clear definition of what exactly a handler is as it relates to jquery. Thanks for your help =]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人间不值得 2024-09-08 12:12:22

处理程序是您编写的用于处理事件的任何函数。例如在

$(document).ready(function() {
      //......
});

处理程序中是

function() {
     //.......
}

Handlers are any functions that you write to handle events. For e.g. in

$(document).ready(function() {
      //......
});

the handler is

function() {
     //.......
}
情域 2024-09-08 12:12:22

将处理程序视为正在调用的任何操作的回调。对于 handler(eventObject) 来说,这意味着带有该参数的方法可以接受传递给它的函数,并且该函数将在该函数之前、期间或之后的某个特定时间点被调用。执行接收它的方法(如参数规范所示),并且将传递一个名为 eventObject 的值,该值可以是任何内容,但很可能是为您发出回调的给定事件的目标。

这是一个示例:

function MyCallback(eventObject) {
    alert(jQuery(eventObject).attr('id') + ' toggled'));
}

jQuery("#myBtn").click(function() {
    jQuery("#myObj").toggle("fast", function(eventObject) { MyCallback(eventObject); });
});

使用上面的代码,当单击 #myBtn 时,元素 #myObj 将被切换(快速),并且一旦切换动画完成 MyCallback 将被调用并传递 #myObj,这将导致出现一条警告,提示“myObj 已切换”。

Think of a handler as a callback for whatever operation is being invoked. In the case of handler(eventObject) it means that the method with that parameter can accept a function being passed to it and that function will be called at some specific point in time before, during, or after the execution of the method receiving it (as indicated by the parameter specification) and it will be passed a value called eventObject which can be anything, but is most likely the target of the given event your callback is being issued for.

Here's an example:

function MyCallback(eventObject) {
    alert(jQuery(eventObject).attr('id') + ' toggled'));
}

jQuery("#myBtn").click(function() {
    jQuery("#myObj").toggle("fast", function(eventObject) { MyCallback(eventObject); });
});

With the above code, when #myBtn is clicked the element #myObj will be toggled (fast) and as soon as the toggle animation completes MyCallback will be called and passed #myObj which will cause an alert to appear saying, "myObj toggled".

我恋#小黄人 2024-09-08 12:12:22

这是处理事件的函数。为了扩展,在切换的情况下,ON 调用第一个函数(使用 eventObject),OFF 调用第二个函数。 eventObject 将根据事件保存不同的信息,例如鼠标的坐标。

This is the function which will handle the event. To expand, in the case of toggle, ON calls the first function (with the eventObject) and OFF calls the second function. eventObject will hold different info depending on events, like coordinates of the mouse.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文