点dt显示dd的高度,如果用全局变量会产生冲突,解决的办法是将全局的变成局部的
-------全局变量有问题----------
var flag = true;
$(".accountList2 dt").click(function(){
if(flag){
$(this).next().animate({height : "10px"}, 300);
}else{
$(this).next().animate({height : "0"}, 300);
flag=false;
}
flag =!flag;
});
-------这样可以改成变量有问题----------
$(".accountList2 dt").each(function() {
var flag = true;
$(this).click(function() {
if (flag) {
$(this).next().animate({
height: "10px"
}, 300);
} else {
$(this).next().animate({
height: "0"
}, 300);
flag = false;
}
flag = !flag;
});
});
---html---
<dl class="accountList2">
<dt>股东0001</dt>
<dd>........</dd>
<dt>股东0002</dt>
<dd>........</dd>
<dt>股东0003</dt>
<dd>........</dd>
</dl>