0

is there any way to add jquery ready() function to a code like this?

<script type='text/javascript' src='http://xxxxxxxxxxx?id=35&amp;k=bf6ee6f24e058a864298&amp;method=div' id='block-4e058a8642973ae2c431f0d8'></script>

suppose we can't add ready function within the actual js code in that src link

if we can't, then is there anyway to make this script load last?

4

4 回答 4

0

Yes. If you know jQuery will be loaded prior to this line you can have the content contained in the following in the external file.

$(function () {
   // file content here
});

If you can't change the target file there are also script loading plugins that will allow control over when things are loaded. This is easiest way.

For example yep/nope is popular. http://yepnopejs.com/

于 2013-02-02T01:18:17.730 回答
0

Simple answer you cant, without having the jquery library added.

but if you place the script just before the final </html> tag it should execute last.

于 2013-02-02T01:18:48.860 回答
0

2 simple ways:

  1. Put the script tag at the bottom of your page.
  2. Create it dynamically with JS and add it to the page after your other scripts using something like:
Example:
window.onload = function() {
     var s = document.createElement('script');
     s.src = "http://yourscripthere";
     document.body.appendChild(s);
}
于 2013-02-02T01:20:25.850 回答
0

I get the impression it's because you want to change something in the src

$(function(){
    var your_id=35;
    $.getScript('http://xxxxxxxxxxx?id=' + your_id + '&amp;k=bf6ee6f24e058a864298&amp;method=div');
});

or if you want it to load after everything else has loaded

$(window).load(function(){
    var your_id=35;
    $.getScript('http://xxxxxxxxxxx?id=' + your_id + '&amp;k=bf6ee6f24e058a864298&amp;method=div');
});
于 2013-02-02T01:43:21.153 回答