关于jquery插件定义。何时运行?

关于jquery插件定义。何时运行?,jquery,Jquery,我最近学习了jquery插件。但是我有一些困惑。比如: <!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> </head> <bo

我最近学习了jquery插件。但是我有一些困惑。比如:

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
  </head>
<body>
<script type="text/javascript">
  (function ($){
    $.fn.xxx=function(){
      console.log("define xxx");
    }
  })(jQuery)
</script>
</body>
</html>

(函数($){
$.fn.xxx=函数(){
console.log(“定义xxx”);
}
})(jQuery)

为什么控制台不打印任何内容?

您正在定义一个函数,但没有调用它

如果要查看某些内容,请调用函数:

<script type="text/javascript">
  (function ($){
    $.fn.xxx=function(){
      console.log("define xxx");
    }
  })(jQuery)
  jQuery(function(){
      jQuery(document).xxx();
  });
</script>

(函数($){
$.fn.xxx=函数(){
console.log(“定义xxx”);
}
})(jQuery)
jQuery(函数(){
jQuery(document.xxx();
});

您现在也需要调用该函数,您只是在定义它

$().xxx()

定义函数时,console.log()不应该运行?定义函数不会调用它。