直接上代碼,不信自己測。
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>jquery</title>
</head>
<body>
<h5>判斷jquery是否加載</h5>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
if (typeof jQuery != 'undefined') {
alert("jquery已經被加載");
}
else
{
alert("jquery沒有被加載");
}
</script>
</body>
</html>
主要講兩點:
1.有圖有真相
2.通過注釋jquery可以判斷是否引入。