批改狀態(tài):未批改
老師批語:
今天來說說常見的jquery引入方式與加載
在head里引入jQuery的庫
可以在jQuery官網(wǎng)或者百度cdn等等引入或下載
下載與引入地址:http://jquery.com/
<head> <title>jQuery</title> <!-- 第一種引入方式 --> <script type="text/javascript" src="jquery.js"></script> <!-- 第二種 --> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> </head>
引入之后就是加載嘍
簡寫形式
<script type="text/javascript"> $(function(){ alert(加載完畢:第1種) }) </script>
非簡寫
<script type="text/javascript"> $(document).ready(function(){ alert(加載完畢:第2種) }); </script>
在把原生的寫上對(duì)比一下吧
<script type="text/javascript"> window.onload(function(){ alert('原生加載') }) </script>
<!DOCTYPE html> <html> <head> <title>jQuery</title> <!-- 第一種引入方式 --> <!-- <script type="text/javascript" src="jquery.js"></script> --> <!-- 第二種 --> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ alert('加載完畢...') }) </script> </head> <body> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)