在我的代碼中,我有一個外部腳本,它爲我的頁面添加了一些元素。這個腳本的document.ready後異步加載:Jquery從外部腳本加載元素
<script src="http://any.com/script.js"></script>
此腳本包含未來:
$.ajax({
url: '/anyScript',
complete: function(){
alert('yo'); // FIRED
$('body').append('<div id="xxx" />'); // FIRED
}
});
我需要等到該元素將出現一些樣式添加到它
$(function(){
$('body').on('load','#xxx', function(){
$(this).css({
background:'red',
width: 100,
height: $('#first_el').height()
});
});
});
這不會觸發。該怎麼辦?
更新:http://jsfiddle.net/81ucdoLo/1/
是的,我認爲唯一一種間隔的方法。這對我來說很有用。謝謝! – 2014-09-25 08:23:13