我的要求如下:
div
<script>...</script>
$('document').ready( ... )
function AjaxLoaded() {
$(‘document’).trigger(‘ready’); }
恐怕这并没有解决。
我已经看到了一些 关于响应,它们通过更改AJAX上返回的代码来“规避”这个问题(使其成为函数,并在加载后调用它,或者只是删除$(document).ready())。我需要强调的是,在这种情况下,我无法更改检索到的代码。
$(document).ready()
经过一些研究,我创造了一种使其工作的方法。
这是我的测试,表明它可以正常工作:http : //www.antiyes.com/test/test2.php
这是相关代码:
<script> // easy copy of an array Array.prototype.copy = function() { return [].concat(this); }; // this function is added to jQuery, it allows access to the readylist // it works for jQuery 1.3.2, it might break on future versions $.getReadyList = function() { if(this.readyList != null) this.myreadylist = this.readyList.copy(); return this.myreadylist; }; $(document).ready(function() { alert("blah"); }); </script> <script> // this should be added last so it gets all the ready event $(document).ready(function() { readylist = $.getReadyList(); }); </script>
然后在体内我有:
<input type="button" onclick="$(readylist).each(function(){this();});" value="trigger ready" />
基本上,我所做的就是在jQuery中添加了一个函数,该函数在清除readyList之前将其复制出来,然后可供您使用。
看起来下面的代码不起作用:
function AjaxLoaded() { $(document).trigger('ready'); }
删除报价document。
document