admin 管理员组文章数量: 1086019
I am currently testing this in Mozilla FireFox 3.0.5 using FireBug 1.3.0 with jQuery 1.2.6.
First try
document.getElementById("x").onfocus = function ()
{
var helloWorld = "Hello World";
};
FireBug console:
document.getElementById("helloworld").onfocus.toString() = function body as a string
$("#helloworld").get(0).onfocus.toString() = function body as a string
Second try
$("#helloworld").focus(function ()
{
var helloWorld = "Hello World";
});
FireBug console:
document.getElementById("helloworld").onfocus.toString() = FireBug returns nothing
$("#helloworld").get(0).onfocus.toString() = FireBug returns nothing
What am I missing here? Why can't I find the callbacks when attaching them with jQuery?
I am currently testing this in Mozilla FireFox 3.0.5 using FireBug 1.3.0 with jQuery 1.2.6.
First try
document.getElementById("x").onfocus = function ()
{
var helloWorld = "Hello World";
};
FireBug console:
document.getElementById("helloworld").onfocus.toString() = function body as a string
$("#helloworld").get(0).onfocus.toString() = function body as a string
Second try
$("#helloworld").focus(function ()
{
var helloWorld = "Hello World";
});
FireBug console:
document.getElementById("helloworld").onfocus.toString() = FireBug returns nothing
$("#helloworld").get(0).onfocus.toString() = FireBug returns nothing
What am I missing here? Why can't I find the callbacks when attaching them with jQuery?
Share Improve this question edited Jan 14, 2009 at 12:24 cllpse asked Jan 14, 2009 at 11:58 cllpsecllpse 21.7k37 gold badges133 silver badges170 bronze badges2 Answers
Reset to default 6To view events that jQuery has bound use :
$("#helloworld").data('events');
If you bind the focus as per your example and you run the above in firebug console it will return
Object focus=Object
jQuery doesn't attach the callbacks directly, instead it stores them internally in a registry. Whenever an event is triggered, jQuery looks in the registry and calls the callback that you asked for earlier.
This gives you the advantage of being able to stack multiple callbacks onto a single element's event, but it has the disadvantage that you must use jQuery's event handler routines to set, get, and remove the callbacks.
本文标签: javascriptFind callback functions added with jQuery on DOM elementsStack Overflow
版权声明:本文标题:javascript - Find callback functions added with jQuery on DOM elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744018183a2519310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论