alismith
پنج شنبه 12 اسفند 1389, 12:16 عصر
سلام لطفا ببینید می تونید مشکل این کد رو پیدا کنید
alert() گذاشتم تا نشون بده شرط کار می کنه
<!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>Untitled Document</title>
<style type="text/css">
.box{
width: 200px;
height: auto;
background: #666;
float: left;
margin-right: 5px;
}
.shcp{
text-decoration: none;
}
</style>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script language="javascript" type="application/javascript">
$(document).ready(function(){
$(".shcp").click(function(){
//set height of parent div
var height = $(this).parent('div').height();
if(height!='20'){
$(this).parent('div').animate({
height: '20px'
},"slow");
alert(height);
}else{
$(this).parent('div').animate({
height: 'auto'
},"slow");
}
});
});
</script>
</head>
<body>
<div class="box"><a class="shcp" href="">[show/hide]</a><br/>row1<br/>row2<br/><br/></div>
<div class="box"><a class="shcp" href="">[show/hide]</a><br/>row1<br/>row2<br/></div>
</body>
</html>
alert() گذاشتم تا نشون بده شرط کار می کنه
<!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>Untitled Document</title>
<style type="text/css">
.box{
width: 200px;
height: auto;
background: #666;
float: left;
margin-right: 5px;
}
.shcp{
text-decoration: none;
}
</style>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script language="javascript" type="application/javascript">
$(document).ready(function(){
$(".shcp").click(function(){
//set height of parent div
var height = $(this).parent('div').height();
if(height!='20'){
$(this).parent('div').animate({
height: '20px'
},"slow");
alert(height);
}else{
$(this).parent('div').animate({
height: 'auto'
},"slow");
}
});
});
</script>
</head>
<body>
<div class="box"><a class="shcp" href="">[show/hide]</a><br/>row1<br/>row2<br/><br/></div>
<div class="box"><a class="shcp" href="">[show/hide]</a><br/>row1<br/>row2<br/></div>
</body>
</html>