google.setOnLoadCallback with jQuery $(document).ready(), is it OK to mix?

后端 未结 4 1599
不思量自难忘°
不思量自难忘° 2020-11-30 23:59

I\'m using Google Ajax API and they suggest I use google.setOnLoadCallback() to do various things related to their API but I\'m using also jQuery\'s $(doc

4条回答
  •  眼角桃花
    2020-12-01 00:42

    You pretty much have to do this:

    google.setOnLoadCallback(function() {
      $(function() {
        // init my stuff
      });
    });
    

    You can't do $(document).ready() without $ (the jQuery object) being available, so that needs to go inside the callback. And you can't be sure the document is ready inside the callback, so you have to do ready() too.

提交回复
热议问题