首先来看一段代码:

index.html

<!DOCTYPE html>
<html>
  <head>

  </head>
  <body>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script id="script" type="text/javascript" src="index01.js"></script>
  </body>
</html>

index01.js

function test() {
  console.log('aaa');
  var script = document.getElementById('script');
  console.log('script:', script);
  console.log('jquery:', $(script));
}
test();

浏览器打印结果:

jquery的$(),到底做了什么事情

当看到这个打印结果后,开始疑惑,到底jquery的$()做了哪些事情呢?其实就是,jquery把元素包装成为了jquery的实例,这个实例继承了jquery的原型方法,这样子我们才能使用jquery的方法。

相关文章:

  • 2021-07-13
  • 2022-12-23
  • 2021-11-18
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-12-02
猜你喜欢
  • 2022-03-09
  • 2022-12-23
  • 2021-08-15
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案