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

admin4年前前端技术1164
<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>


相关文章

分享与定时自动跳转

<!DOCTYPE html> <html> <head> <meta charset="utf-8">...

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

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

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

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

whatsapp浮动按钮

whatsapp浮动按钮

whatsapp浮动按钮whatsapp.zip...

Navigate down the menu through jquery development

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

原生javascrip 复制功能

兼容chrome FIrfox IE 下载地址000.zip代码如下:<!DOCTYPE html> <html> <head> &nbs...

发表评论    

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