简体   繁体   English

在加载后将字符串附加到future元素(jquery)

[英]Append string to future element after it will be loaded (jquery)

Need something like this (for future loaded html to page!): 需要这样的东西(以后加载的html到页面!):

$(document).on('ready', 'a', function(){ $(this).after('it works'); });

This doesn't work (need similar event, like 'load' or 'ready' to fire after element will be added to the page ). 这不起作用(需要类似的事件,比如'load'或'ready' ,在将元素添加到页面后触发 )。 For example another event: 例如另一个事件:

$(document).on('mouseover', 'a', function(){ $(this).after('it works'); });

working normaly. 正常工作。 Any suggestions? 有什么建议么?

That's probably because these elements don't fire onload events. 这可能是因为这些元素不会触发onload事件。 The document 's load event is fired after all elements have loaded, so you can try using that. load所有元素后会触发documentload事件,因此您可以尝试使用它。

$(document).on('DOMNodeInserted', 'a', function(){ $(this).after('it works'); });

Demo 演示

I am not sure if it will help, but try using .live 我不确定它是否有帮助,但尝试使用.live

http://api.jquery.com/live/ http://api.jquery.com/live/

$.ajaxComplete()? $ .ajaxComplete()? Or just CSS? 或者只是CSS?

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

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