admin管理员组文章数量:1316509
Forgive my ignorance as I am not as familiar with jquery. Is there an equivalent to dojo.connect() ?
I found this solution : /
But there isn't disconnect feature !
Do you know other solution in jquery ? There are jquery.connect but this plugin not work in my tests.
Thanks for your help,
Stephane
Forgive my ignorance as I am not as familiar with jquery. Is there an equivalent to dojo.connect() ?
I found this solution : http://think-robot./2009/06/hitch-object-oriented-event-handlers-with-jquery/
But there isn't disconnect feature !
Do you know other solution in jquery ? There are jquery.connect but this plugin not work in my tests.
Thanks for your help,
Stephane
- Note that dojo.connect is being replaced by the dojo/on function: dojotoolkit/reference-guide/1.8/dojo/on.html – Steve Wranovsky Commented Oct 12, 2012 at 4:03
4 Answers
Reset to default 3The closest equivalent jQuery has is .bind()
, for example:
$("#element").bind('eventName', function(e) {
//stuff
});
And .unbind()
to remove the handler, like this:
$("#element").unbind('eventName');
There are also shortcuts for .bind()
, so for example click
can be done 2 ways:
$("#element").bind('click', function() { alert('clicked!'); });
//or...
$("#element").click(function() { alert('clicked!'); });
There is also .live()
(.die()
to unbind) and .delegate()
(.undelegate()
to unbind) for event handlers based on bubbling rather than being directly attached, e.g. for dynamically created elements.
The examples above were anonymous functions, but you can provide a function directly just like dojo (or any javascript really), like this:
$("#element").click(myNamedFunction);
What do you mean by an equivalent to dojo.connect() ?
If you are willing to create your own custom event handlers, look at bind(), trigger() and proxy() in the Events.
The proxy() function will alow your to redefine what this points to in your callback function.
jQuery connect is equivalent to dojo.connect.
There isn't as such but you can acheive the same thing as follows:
$('#someid').click(function() { SomeFunc($(this)) });
That will wire somefunc, to the click event of control with id "someid". When the control is clicked the function will be called and the parameter will be a jquery object that refers to control that was clicked.
Update I have just done a bit more research and i think .delegate() is closer to what you want.
本文标签: javascriptdoes jquery have an equivalent of dojoconnect()Stack Overflow
版权声明:本文标题:javascript - does jquery have an equivalent of dojo.connect()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741978075a2408237.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论