jQuery 与 $ 符号的区别

379 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="jquery-3.4.1.js"></script>
  <script>
    console.log($);
    /*
      ƒ ( selector, context ) {

        // The jQuery object is actually just the init constructor 'enhanced'
        // Need init if jQuery is called (just allow error to be thrown if not included)
        return new jQuery…
    */
    console.log(jQuery);
     /*
      ƒ ( selector, context ) {

        // The jQuery object is actually just the init constructor 'enhanced'
        // Need init if jQuery is called (just allow error to be thrown if not included)
        return new jQuery…
    */
    console.log($ === jQuery); // true

    // 这两种书写方式都是一个意思
    // 使用 $ 符号的原因: 书写简洁,相当于其他字符与众不同,容易被记住。
    // $(document).ready(function () {

    // })

    // jQuery(document).ready(function () {
      
    // })
  </script>
</head>
<body>
  
</body>
</html>