简体   繁体   English

假jquery document.ready在没有jquery的页面上调用

[英]fake jquery document.ready calls on pages without jquery

I wanted to use some data in another JS script which had a JQuery call $(document).ready(function() inside the block, but i did not want to use JQuery nor init the script, because i just wnat to use some of the predefined variables. 我想在另一个JS脚本中使用一些数据,该脚本在块内有一个JQuery调用$(document).ready(function(),但是我不想使用JQuery也不初始化该脚本,因为我只是想使用其中的一些预定义的变量。

So simply using the script from external source ( as it might get changed ) but skipping the ready() call and just do some data manipulation afterwards. 因此,只需使用来自外部源的脚本(因为它可能会更改),但跳过ready()调用,然后再执行一些数据操作即可。

I got it working with 我明白了

<script>
var fakeJquery = function(fn) {
    this.ready = function () {
        return true;
    }
};
var $ = function(fn) { return new fakeJquery();}
</script>

But i wonder if there is a better, easier way to do that? 但是我想知道是否有更好,更容易的方法呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM