Jquery initialization function is almost used to any website, we sometimes do forget how to use the jquery init method, so I want to write an article as my notes.
How does the jquery initialize? First we need to import the jquery package, as follows:
- <script type="text/javascript" src="./js/jquery.min.js"></script>
We have four common jquery init method
Jquery init method one:
- <script type="text/javascript">
- $(document).ready(function(){
-
- console.log("enter jquery init method one...");
-
- });
- </script>
Jquery init method two:
- <script type="text/javascript">
-
- $(function(){
-
- console.log("enter jquery init method two...");
-
- });
-
- </script>
Jquery init method three:
- <script type="text/javascript">
-
- jQuery(function($){
-
- console.log("enter jquery init method three...");
-
- });
-
- </script>
Jquery init method four:
- <script type="text/javascript">
-
- (function ($) {
- console.log("enter jquery init method four...");
- })(jQuery);
- </script>
note:
If we use original JavaScript, we want to use the init method, we don't need to import the jquery.min.js package. We can use the onload method inside <body> tag, as follows:
- <script type="text/javascript">
- window.onload=function(){
- //write something
- }
- </script>
Thank you!
No comments:
Post a Comment
Note: only a member of this blog may post a comment.