Tag: delegates

替代jquery live可以工作

我有这个简单的代码。 http://jsfiddle.net/borth/BmEZv/如果你点击链接一次,它可以正常工作。 如果再次单击它,则不起作用。 由于在加载DOM后html被加载到html中,我尝试过.on,.bind,.delegate和.live。 除了被弃用的.live之外,它们都没有用(我使用的是jquery 1.7.2)。 有人可以解释为什么.live是唯一有效的function,以及为什么其他function不起作用(或者如果我对其他function做错了)。 $(document).ready(function(){ $(“.OpenPopup”).bind(‘click’, function(e){ alert(‘test .OpenPopup’); // do something return false; }); $(“.EditIcon”).bind(‘click’, function(){ alert(‘test .EditIcon’); // do something $(“#ABC”).html(‘click here again’); }); }); click here

有没有办法在jQuery中委托事件一?

我想将事件委托给点击一个 。 有谁知道是否可以这样做?

获得原始目标的最佳方式

什么是jQuery喜欢和/或最佳实践方式来获取jQuery(或一般的浏览器javascript)中的事件的原始目标。 我一直在用这样的东西 $(‘body’).bind(‘click’, function(e){ //depending on the browser, either srcElement or //originalTarget will be populated with the first //element that intercepted the click before it bubbled up var originalElement = e.srcElement; if(!originalElement){originalElement=e.originalTarget;} }); 哪个有效,但我对两线function嗅探并不满意。 有没有更好的办法?