让javascrip函数内的局部变量能为全局使用的方法

admin5年前前端技术1318
<script type="text/javascript">
  var mine;
 function me() {
   mine=$("#my").html();
    console.log(mine)
 }
 me();
  console.log(mine);
 

</script>

特别注意:

1.jquery 函数内或回调函数内的变量只有同样在另一个回调函数内能公用一个变量;

2.外部用var定义这个变量,那么内部就不能var这个保留字定义这个变量

3.或者变量不用var去定义,代码如下:

<script type="text/javascript">
 
 function me() {
   mine=1;
    console.log(mine)
 }
 me();
  console.log(mine);
 

</script>


相关文章

Navigate down the menu through jquery development

The core knowledge is to use jquery's hover method to achieve, The animation effe...

jquery如何获取div里面value的值以及原生写法

jquery写法$(this).attr("value")原生写法var value = document.getElementById(""+id+"...

通过jquery开发导航下来菜单

核心知识是用jquery的hover方法去实现,动画效果是slideDown与slideUp代码下载地址:点击下载...

webpack全局安装了,使用命令时却提示安装脚手架

全局安装了webpack ,使用webpack的时候,却有如下的提示One CLI for webpack must be installe...

jquery默认设置第一个类的css或者属性

var me=$("#cima>input");me.eq(0).css...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。