戻る

記述場所

head要素内に記述する場合

一般的な方法ですすが、公開する前には、できるだけ外部ファイルまとめたほうがよい。

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="content-script-type" content="text/javascript">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQueryの処理を記述 
</script> 
<title></title>
</head>

外部ファイルに記述する場合

一般的な方法です。

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="content-script-type" content="text/javascript">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src=" 外部ファイルにjQueryの処理を記述 "></script> 
<title></title>
</head>

body要素の途中に記述する場合

ブログなどでhead要素内に記述できない場合や、外部から読み込むファイルにのjQueryを使用する場合に使用。

<body>
(省略)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQueryの処理を記述
</script>
(省略)
</body>

body要素を閉じる直前に記述する場合

JavaScriptの読み込みを後回しにすることで、HTMLの表示速度を優先することもある。

<body>
(省略)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQueryの処理を記述
</script>
</body>
</html>

inserted by FC2 system