js 方法点击第一次进入一次 点击第二次进入两次 以此类推

   $('#centre li:has(ul)').children(':first-child').click( function(e){
    // element vars
    var el = $(this).parent().children('ul').first();
    var isOpen = $(this).parent().hasClass('mtree-open');
     alert(isOpen);
    console.log($(this).parent().html());
    // force auto height of element so actual height can be extracted 力汽车元素,所以实际高度的高度可以提取
    el.css({'height': 'auto'}); 
    // Velocity.js animate element Velocity.js 动画元素
     if($.Velocity) {
      el.velocity('stop').velocity({
      //  translateZ: 0, // optional hardware-acceleration is automatic on mobile  可选硬件加速的自动移动
        height: isOpen ? [0, el.outerHeight()] : [el.outerHeight(), 0] 
       },{
        queue: false,
        duration: duration,
         easing: easing,
         display: isOpen ? 'none' : 'block',
         begin: setNodeClass($(this).parent(), isOpen),
         complete: function(){
           if(!isOpen) $(this).css('height', 'auto');
         }
       });
    //jQuery fallback animate element jQuery后备动画元素
     } else {
      setNodeClass($(this).parent(), isOpen);
       el.slideToggle(duration);
     } 
    // We can't have nodes as links unfortunately  不幸的是我们不能有节点链接
    //e.preventDefault();
    });  

html的格式是

多层嵌套的 是一个树形

第一次点击执行一次第二次执行2次?

你是不是树形 加载的时候 你点击树形节点 加载的节点是你全部的节点

看是不是绑定重复了,每次在树形遍历

$('#centre li:has(ul)').children(':first-child').click( function(e){

执行的上下文代码发来看来

都是执行了这个点击事件还是其他的?

//中央
function centre(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findProvince",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#province li').remove();
$('#city li').remove();
$('#county li').remove();
$('#township li').remove();
$('#village li').remove();
$("#province").append(data.provinceStr);
tree();
}
});

}
//省
function province(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findCity",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#city li').remove();
$('#county li').remove();
$('#township li').remove();
$('#village li').remove();
$("#city").append(data.cityStr);
tree();
}
});

}
//市
function city(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findCounty",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#county li').remove();
$('#township li').remove();
$('#village li').remove();
$("#county").append(data.countyStr);
tree();
}
});

}
//县
function county(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findTownship",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#township li').remove();
$('#village li').remove();
$("#township").append(data.townshipStr);
tree();
}
});

}
//乡
function township(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findVillage",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#village li').remove();
$("#village").append(data.villageStr);
tree();
}
});

}

 function tree(){
 (function ($, window, document, undefined) {
    var collapsed = false;
    var duration = 200; 
    var listAnim = true;
    var easing = 'easeOutQuart'; 
     //$('#centre ul').css({'overflow':'hidden', 'height': (collapsed) ? 0 : 'auto', 'display': (collapsed) ? 'none' : 'block' });
    // Get node elements, and add classes for styling  得到节点元素,并添加类样式
  var node = $('.mtree li ul li:has(ul)');  
 // alert(node);
   //var node = $('.mtree li ul:has(ul)');  
   node.addClass({'overflow':'hidden', 'height': (collapsed) ? 0 : 'auto', 'display': (collapsed) ? 'none' : 'block' });
   // node.css({'background-color':'red'});
   node.each(function(index, val) {
  //alert("index"+index+"val"+val);
       $(this).children(':first-child').css('cursor', 'pointer');
      // alert($(this).hasClass('mtree-closed'));
       if(!$(this).hasClass('mtree-closed')&&!$(this).hasClass('mtree-open')) {
         $(this).addClass('mtree-node mtree-' + ((collapsed) ? 'closed' : 'open'));
       }
       $(this).children('ul').addClass('mtree-level-' + ($(this).parentsUntil($('ul.mtree'), 'ul').length + 1));
  });

  // Set mtree-active class on list items for last opened element    设置mtree-active类最后打开元素的列表项
  $('.mtree li > *:first-child').on('click.mtree-active', function(e){
   // $(this).parent().addClass({'overflow':'hidden', 'height': (collapsed) ? 0 : 'auto', 'display': (collapsed) ? 'none' : 'block' });
     if($(this).parent().hasClass('mtree-closed')) {
      $('.mtree-active').not($(this).parent()).removeClass('mtree-active');
      $(this).parent().addClass('mtree-active');
    } else if($(this).parent().hasClass('mtree-open')){
      $(this).parent().removeClass('mtree-active'); 
    } else {
      $('.mtree-active').not($(this).parent()).removeClass('mtree-active');
      $(this).parent().toggleClass('mtree-active'); 
    } 
  });

$('#centre li:has(ul)').children(':first-child').click( function(e){
// element vars
var el = $(this).parent().children('ul').first();
var isOpen = $(this).parent().hasClass('mtree-open');
alert(isOpen);
console.log($(this).parent().html());
// force auto height of element so actual height can be extracted 力汽车元素,所以实际高度的高度可以提取
el.css({'height': 'auto'});
// Velocity.js animate element Velocity.js 动画元素
if($.Velocity) {
el.velocity('stop').velocity({
// translateZ: 0, // optional hardware-acceleration is automatic on mobile 可选硬件加速的自动移动
height: isOpen ? [0, el.outerHeight()] : [el.outerHeight(), 0]
},{
queue: false,
duration: duration,
easing: easing,
display: isOpen ? 'none' : 'block',
begin: setNodeClass($(this).parent(), isOpen),
complete: function(){
if(!isOpen) $(this).css('height', 'auto');
}
});
//jQuery fallback animate element jQuery后备动画元素
} else {
setNodeClass($(this).parent(), isOpen);
el.slideToggle(duration);
}
// We can't have nodes as links unfortunately 不幸的是我们不能有节点链接
//e.preventDefault();
});

function setNodeClass(el, isOpen) {
if(isOpen) {
el.removeClass('mtree-open').addClass('mtree-closed');
} else {
el.removeClass('mtree-closed').addClass('mtree-open');
}
}
/* if($.Velocity && listAnim) {
$.Velocity.Sequences.list = function (element, options, index, size) {
$.Velocity.animate(element, {
opacity: [1,0],
translateY: [0, -(index+1)]
}, {
delay: index*(duration/size/2),
duration: duration,
easing: easing
});
};
} */
var a=$('.mtree').css('opacity');
if( a== 0) {
if($.Velocity) {
$('.mtree').css('opacity', 1).children().css('opacity', 0).velocity('list');
} else {
$('.mtree').show(200);
}
}
}(jQuery, this, this.document));
}

//中央
function centre(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findProvince",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#province li').remove();
$('#city li').remove();
$('#county li').remove();
$('#township li').remove();
$('#village li').remove();
$("#province").append(data.provinceStr);
tree();
}
});

}
//省
function province(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findCity",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#city li').remove();
$('#county li').remove();
$('#township li').remove();
$('#village li').remove();
$("#city").append(data.cityStr);
tree();
}
});

}
//市
function city(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findCounty",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#county li').remove();
$('#township li').remove();
$('#village li').remove();
$("#county").append(data.countyStr);
tree();
}
});

}
//县
function county(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findTownship",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#township li').remove();
$('#village li').remove();
$("#township").append(data.townshipStr);
tree();
}
});

}
//乡
function township(id){
$.ajax({
type: "post",//数据发送的方式(post 或者 get)
url: "Level_findVillage",//要发送的后台地址
data: {fatherId:id},
dataType: "json",//后台处理后返回的数据格式
success: function (data) {//ajax请求成功后触发的方法
$('#village li').remove();
$("#village").append(data.villageStr);
tree();
}
});

}

 function tree(){
 (function ($, window, document, undefined) {
    var collapsed = false;
    var duration = 200; 
    var listAnim = true;
    var easing = 'easeOutQuart'; 
     //$('#centre ul').css({'overflow':'hidden', 'height': (collapsed) ? 0 : 'auto', 'display': (collapsed) ? 'none' : 'block' });
    // Get node elements, and add classes for styling  得到节点元素,并添加类样式
  var node = $('.mtree li ul li:has(ul)');  
 // alert(node);
   //var node = $('.mtree li ul:has(ul)');  
   node.addClass({'overflow':'hidden', 'height': (collapsed) ? 0 : 'auto', 'display': (collapsed) ? 'none' : 'block' });
   // node.css({'background-color':'red'});
   node.each(function(index, val) {
  //alert("index"+index+"val"+val);
       $(this).children(':first-child').css('cursor', 'pointer');
      // alert($(this).hasClass('mtree-closed'));
       if(!$(this).hasClass('mtree-closed')&&!$(this).hasClass('mtree-open')) {
         $(this).addClass('mtree-node mtree-' + ((collapsed) ? 'closed' : 'open'));
       }
       $(this).children('ul').addClass('mtree-level-' + ($(this).parentsUntil($('ul.mtree'), 'ul').length + 1));
  });

  // Set mtree-active class on list items for last opened element    设置mtree-active类最后打开元素的列表项
  $('.mtree li > *:first-child').on('click.mtree-active', function(e){
   // $(this).parent().addClass({'overflow':'hidden', 'height': (collapsed) ? 0 : 'auto', 'display': (collapsed) ? 'none' : 'block' });
     if($(this).parent().hasClass('mtree-closed')) {
      $('.mtree-active').not($(this).parent()).removeClass('mtree-active');
      $(this).parent().addClass('mtree-active');
    } else if($(this).parent().hasClass('mtree-open')){
      $(this).parent().removeClass('mtree-active'); 
    } else {
      $('.mtree-active').not($(this).parent()).removeClass('mtree-active');
      $(this).parent().toggleClass('mtree-active'); 
    } 
  });

$('#centre li:has(ul)').children(':first-child').click( function(e){
// element vars
var el = $(this).parent().children('ul').first();
var isOpen = $(this).parent().hasClass('mtree-open');
alert(isOpen);
console.log($(this).parent().html());
// force auto height of element so actual height can be extracted 力汽车元素,所以实际高度的高度可以提取
el.css({'height': 'auto'});
// Velocity.js animate element Velocity.js 动画元素
if($.Velocity) {
el.velocity('stop').velocity({
// translateZ: 0, // optional hardware-acceleration is automatic on mobile 可选硬件加速的自动移动
height: isOpen ? [0, el.outerHeight()] : [el.outerHeight(), 0]
},{
queue: false,
duration: duration,
easing: easing,
display: isOpen ? 'none' : 'block',
begin: setNodeClass($(this).parent(), isOpen),
complete: function(){
if(!isOpen) $(this).css('height', 'auto');
}
});
//jQuery fallback animate element jQuery后备动画元素
} else {
setNodeClass($(this).parent(), isOpen);
el.slideToggle(duration);
}
// We can't have nodes as links unfortunately 不幸的是我们不能有节点链接
//e.preventDefault();
});

function setNodeClass(el, isOpen) {
if(isOpen) {
el.removeClass('mtree-open').addClass('mtree-closed');
} else {
el.removeClass('mtree-closed').addClass('mtree-open');
}
}
/* if($.Velocity && listAnim) {
$.Velocity.Sequences.list = function (element, options, index, size) {
$.Velocity.animate(element, {
opacity: [1,0],
translateY: [0, -(index+1)]
}, {
delay: index*(duration/size/2),
duration: duration,
easing: easing
});
};
} */
var a=$('.mtree').css('opacity');
if( a== 0) {
if($.Velocity) {
$('.mtree').css('opacity', 1).children().css('opacity', 0).velocity('list');
} else {
$('.mtree').show(200);
}
}
}(jQuery, this, this.document));
}