jQuery TipsjQueryの読み込み方法
- jQueryの読み込み方法
- jQueryの読み込み方法〔Google AJAX API使用〕
- jQueryが読み込まれているか確認
jQueryの読み込み方法
unknown
jQueryを使用するには、head要素内で「jquery.js」を読込みます。
設置サンプル
<html> <head> ・・・ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> /* DOMが操作可能になった時に実行 */ $(document).ready(function(){ $("#mes").html("<p>Hello! Internet!</p>"); }); /* 上記の省略形 */ $(function(){ $("#mes").html("<p>Hello! Internet!</p>"); }); </script> ・・・ </head> <body> ・・・ </body> </html>
jQueryの読み込み方法
Google AJAX API使用
unknown
Google AJAX APIローダーの google.load() メソッドを使用して、jQueryを取得して読み込むことも可能です。 使用するライブラリとして「jquery」を指定し、そのバージョン番号を指定するだけで、簡単に利用できます。
設置サンプルサンプルを見る
<script src="http://www.google.com/jsapi"></script> <script type="text/javascript"> /* jQuery v1.3.2を読込む */ google.load("jquery", "1.3.2"); /* ページが完全に読み込まれた時に、処理を実行 */ google.setOnLoadCallback(function() { $("#mes").html("<p>Hello! Internet!</p>"); }); </script>
設置サンプルサンプルを見る
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#mes").html("<p>Hello! Internet!</p>");
});
</script>
jQueryが読み込まれているか確認
unknown
設置サンプルサンプルを見る
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> /* jQuery v1.3.2が読み込まれているか確認 */ $(function(){ /* 例1 */ if(jQuery){ $("#res1").html("<p>jQueryは読込まれています。"+jQuery+"</p>"); } /* 例2 */ if (typeof jQuery!="undefined"){ $("#res2").html("<p>jQueryは読込まれています。typeof jQuery="+typeof jQuery+"</p>"); } }); </script> </head> <body> <div id="wrap"> <div id="res1"></div> <div id="res2"></div> </div> </body> </html>