<!DOCTYpe html> <html> <head> <title> jQuery ready() function </title> <script src = "/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#p1").css({"font-size": "30px", "color": "blue", "background": "yellow", "fontWeight": "bold"}); $("#p2").css({"fontSize": "20px", "fontWeight": "bold", "color": "red"}); $("#p3").css({"color": "blue"}); }); }); </script> </head> <body> <p id = "p1"> Welcome to the lidihuo.com </p> <p id = "p2"> This is an example of using the $(document).ready() function. </p> <p id = "p3"> This is a third paragraph element </p> <p> Click the following button to see the effect. </p> <button> Click me </button> </body> </html>
输出:
Welcome to the lidihuo.com
This is an example of using the $(document).ready() function.