一、
1."$(document).ready(function(){});"也可以簡寫成“$(function(){});”
等這個頁面全部加載完之後就去執行js,函數用於在當前文檔結構載入完畢後立即執行指定的函數,該函數的作用相當於window.onload事件。
二、
<!DOCTYPE html> <html> <head> <<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>hello world</title> <link rel="stylesheet" href="plugs/bootstrap-4.6.1-dist/css/bootstrap.min.css" </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-3" style="background-color: aqua;">3</div> <div class="col-md-9" style="background-color:red;">9</div> </div> <hr /> <p>如果你點我,我就會消失。</p> <p>繼續點我!</p> <p>接着點我!</p> </div> <!-- container-fluid end --> <script src="plugs/jquery-3.6.0.min.js"></script> <script type="text/javascript"> // $(document).ready(function(){ // $("p").click(function(){ // $(this).hide(); // }); // }); $(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </body> </html>