简体   繁体   English

jQuery:使用实时事件添加tabindex属性

[英]jQuery: Use live event to add tabindex attributes

Would like all new elements with class .link to have a tabindex. 希望所有具有类.link新元素都具有一个tabindex。

Delegate/Live does not seem to work: 委托/实时似乎不起作用:

$('body').delegate('.link', 'load', function(event){
   $(this).attr('tabindex',0);
});

Trying to apply this to AJAX loaded elements. 尝试将其应用于AJAX加载的元素。 And using what I found in this answer , which suggests the "load" event may be possible. 并使用我在此答案中发现的结果 ,表明“加载”事件可能是可能的。

I'd like to avoid using trigger, or modifying the AJAX callback. 我想避免使用触发器或修改AJAX回调。

The problem here is that no events are triggered when a new element is inserted into the DOM 1 . 这里的问题是, 将新元素插入DOM 1 时不会触发任何事件 The "solution" (not the one you're looking for, unfortunately) is to set the tabindex from the complete callbacks of your ajax operations. “解决方案”(不幸的是,不是您要找的解决方案)是从ajax操作的complete回调中设置tabindex You may use .ajaxComplete() to setup a global/default callback, but that may introduce new problems (such as having to deal with the order events are fired). 您可以使用.ajaxComplete()设置全局/默认回调,但这可能会带来新的问题(例如必须处理触发的订单事件)。

Well, that's not 100% accurate; 好吧,这不是100%准确; there are the Mutation Events , which are not implemented consistently across different browsers, and are supposed to be replaced by Mutation Observers . 有一些Mutation Events ,它们在不同的浏览器中无法实现一致,因此应该由Mutation Observers代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM