等待css加载

I need load an external css (no server side) dynamically, after that I will execute some functions.

How can I wait the css loading?

Thanks.

You can use jQuery get method. Try this

$.get("stylesheetUrl", function(contents){
   $("<style type=\"text/css\">" + contents + "</style>").appendTo(document.head);
   //Call your functions here
});
    //append your css first
    $('head').append('<link rel="stylesheet" href="http://cdn.sstatic.net/stackoverflow/all.css?v=d4a5c7ca0d4c" type="text/css" />');

    var wait_here = setInterval(function(){
      if($(".element").css("float")=== "left"){
         clearInterval(wait_here)
         // Put your function here which needs to be executed after css load
       }
    },50)

where '50' is the time interval it will keep looping for until the css is loaded. In the if() section check for any css which is supposed to effect the element if its loaded.

**Use only the second section if you do not need the appending.