我应该在哪里把我的JavaScript code? [英] Where should I put my JavaScript code?

查看:98
本文介绍了我应该在哪里把我的JavaScript code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用code为自动完成。在code是这里

I would like to use the code for the auto-complete. The code is here.

<script>
    $(function() {
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
        ];
        $( "#tags" ).autocomplete({
            source: availableTags
        });
    });
    </script>



<div class="demo">

<div class="ui-widget">
    <label for="tags">Tags: </label>
    <input id="tags">
</div>

</div><!-- End demo -->



<div class="demo-description" style="display: none; ">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p>
</div><!-- End demo-description -->

不过,我想不通,我应该把这个code。在头?在身体?

However, I cannot figure out where I should put this code. In head? In body?

推荐答案

您或许应该把你的code就在body标签的结束。

You should probably put your code right at the end of the body tag.

查看史蒂夫索德的高性能网站 - 脚本加载的演变

如果您有多个脚本,包括和需要说服自己,他们会以正确的顺序加载你,检查出的 WebSiteOptimization.com的关于推迟物品属性,在这里你可以看到你的脚本的执行顺序。

If you have multiple script includes and need to convince yourself that they will load in the correct order for you, check out WebSiteOptimization.com's Article on the Defer Attribute, where you can see the order your scripts execute.

这篇关于我应该在哪里把我的JavaScript code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆