jsdom and $(document).ready

戏子无情 提交于 2019-12-05 22:51:27

jQuery hasn't loaded when your script is parsed for the first time, so $ isn't defined. This means that $(document).ready isn't defined, so your function isn't set. You should have seen a warning about this in the console. The solution is to make sure jQuery has loaded before creating your document.ready function. I'm not familiar with jsdom, but there are 2 ways to go about this:

  1. Move the generated <script> tag above your inline script. This may or may not be possible with jsdom.
  2. Move your inline script inside the jsdom callback, where you have all the console.log functions. Because by this point jQuery has been loaded. Edit: actually I think jsdom is like a preprocessor? In which case this one won't work, and you need to do (1).
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!