在页面初始加载后加载jQuery库

ken*_*ntz 0 javascript jquery

我有一个案例,我需要检查页面上是否存在jQuery,如果没有,我需要加载它.我创建一个脚本标记并引用外部jQuery库.在继续使用脚本的其余部分之前,如何等待在页面上加载库?

更新:

继祗园的建议后,看起来是什么样的:

if (typeof jQuery === 'undefined') {
    var j = document.createElement('SCRIPT');
    j.type = 'text/javascript';
    j.src = '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
    document.getElementsByTagName('head')[0].appendChild(j);
    j.onload = function () {
        var section = document.createElement('DIV');
        section.setAttribute('style', 'height:300px; width:250px; position: fixed; right: 0px; top: 100px;z-index: 9999; border-style:solid;border-width:1px;');
        section.innerHTML = '<p>steps</p><textarea name="steps"></textarea><p>expected results</p><textarea name="results"></textarea><p><input type="button" name="submit" value="add test case" /></p>';

        document.getElementsByTagName('body')[0].appendChild(section);
    };  
} 
Run Code Online (Sandbox Code Playgroud)

gio*_*_13 6

<script type="text/javascript">
    if(typeof jQuery === 'undefined')
        document.write('<sc'+'ript type="text/javascript" src="jquery.js"></scrip'++'t>');
    window.onload = function(){
        // jquery should be present here
    });
</script>
Run Code Online (Sandbox Code Playgroud)