jQuery .delegate()在load和changeData事件上不起作用 [英] jQuery .delegate() not working on load and changeData events
本文介绍了jQuery .delegate()在load和changeData事件上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以启发我了解jQuery委托,处理什么事件以及不处理什么事件.以下代码无效
Can someone enlighten me on the jQuery delegate, what events are handled and what aren't. The follow code doesn't work
$("#browser").delegate( ".photo", {
"load": function(e) {
alert("photo loaded");
}
});
但是以下代码可以工作
$(".photo").load( function(e) {
alert("photo loaded");
} );
我还尝试将changeData事件委托给一个也不起作用的类
I also try to delegate changeData event to a class which doesn't work as well
$("#browser").delegate( ".thumbnail", {
"changeData": function(e, prop, value) {
alert( prop + " = " + value );
}
});
但是以下代码可以工作
$(".thumbnail").bind( "changeData", function(e, prop, value) {
alert( prop + " = " + value );
}
推荐答案
否:
$("#browser").delegate( ".photo", {
"load": function(e) {
alert("photo loaded");
}
});
但是:
$("#browser").delegate( ".photo", "load",
function(e) {
alert("photo loaded");
});
您不能将实时和委托与这些事件一起使用,因为它们不会冒泡.
And you cannot use live and delegate with those events, because they don't bubble.
这篇关于jQuery .delegate()在load和changeData事件上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文