gpt4 book ai didi

javascript - 我应该把 JavaScript 代码放在哪里?

转载 作者:数据小太阳 更新时间:2023-10-29 05:06:38 24 4
gpt4 key购买 nike

我想使用自动完成代码。密码是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 -->

但是,我不知道应该把这段代码放在哪里。在头上?在体内?

最佳答案

根据 w3schools

何时将脚本放在 HEAD 中

Scripts to be executed when they are called, or when an event is triggered, are placed in functions. Put your functions in the head section, this way they are all in one place, and they do not interfere with page content.

什么时候把脚本放在BODY中

If you don't want your script to be placed inside a function, or if your script should write page content, it should be placed in the body section.

所以在你的情况下。您可以将脚本放在 body

关于javascript - 我应该把 JavaScript 代码放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4647806/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com