日期:2014-05-16  浏览次数:20394 次

代码没有执行????

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
    
$(function(){
       var len=2;//控制要显示的数量
   var arr=$(".div_d:not(:hidden)");
   var gao=$(".div_d").height()*($(".div_d").length/2);
   var xgao=$(".div_d").height()
       
   if(arr.length>len){
   $('.div_d:gt('+(len-1)+')').hide();
   }
   $('.div_btn').click(function(){
  
   if(arr.length>len){
   $('.div_d:gt('+(len-1)+')').show(); 
   $('.div_c').height(gao);
   }
   else
   {
    $('.div_d:gt('+(len-1)+')').hide(); 
$('.div_c').height(xgao);
 alert(1111)   
   }
   })
    })
});
</script>
<style type="text/css">
*{
margin:0;
padding:0;
}
.div{
width:800px;
float:left;
}
.div_c{
width:800px;
height:320px;
float:left;
}
.div_d{
width:373px;
height:300px;
border:1px solid #BFBFBF;
float:left;
margin-right:10px;
margin-top:10px;
}
.div_btn{
width:800px;
height:30px;
float:left;
background:#099;
color:#FFF;
line-height:30px;
text-align:center;
margin-top:20px;
cursor:pointer;
}
</style>
</head>

<body>
<div class="div">
 <div class="div_c">
  <div class="div_d"></div>
  <div class="div_d"></div>
  <div class="div_d"></div>
  <div class="div_d"></div>
  <div class="div_d"></div>
  <div class="div_d"></div>
 </div>
 <div class="div_btn">点击</div>
</div>
</body>
</html>



请问下为什么这段代码没有执行
 else
   {
    $('.div_d:gt('+(len-1)+')').hide(); 
$('.div_c').height(xgao);
 alert(1111)   
   }

------解决方案--------------------
你这个就不用设置高度,隐藏起来就用内部容器的高度就好了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script