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

怎么判断div里面文字有多少

<!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>
<style type="text/css">
*{
margin:0;
padding:0;
}
body{
font-size:12px;
}
.div{
width:465px;
border:1px solid #DCDCDC;
float:left;
}
.div_1{
width:465px;
height:94px;
float:left;
overflow:hidden;
line-height:25px;
}
.div_a{
float:right;
}
</style>
</head>

<body>
<div class="div">
 <div class="div_1">
 福建,在周朝为七闽地,春秋以后为闽越地。秦置闽中郡,中央政权始达于福建。汉初为闽越国疆域,闽越福建——安溪.中国茶都福建——安溪.中国茶都(4张)
北迁之后,自汉始元二年(前85年)汉承认冶县、置东部都尉开始,中经东部都尉从冶县迁到章安(回浦),留下候官管理冶县,到设立南部都尉,再到建安十二年(207年)正式成立建安郡止,福建都在王朝军事管制之下。三国时属吴国,设建安郡,辖建安、南平、将乐、建平(建阳)、东平(松溪)、昭武、吴兴(浦城)以及候官、东安(南安、同安)共9县。
 </div>
 <a href="javascript:;">展开</a>
</div>
</body>
</html>


请问下 当div_1里面的文字没有超过div高度的时候 a标签不显示 当div_1里面的文字超过隐藏了 a标签显示 并且点击a标签的时候 把隐藏的文字显示
------解决方案--------------------

<!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>
<style type="text/css">
*{
margin:0;
padding:0;
}
body{
font-size:12px;
}
.div{
width:465px;
border:1px solid #DCDCDC;
float:left;
}
.exp{
width:465px;
height:94px;
float:left;
line-height:25px;
overflow:hidden;
}
.fold{
width:465px;
float:left;
line-height:25px;
}
.div_a{
float:right;
}
</style>
<script>
window.onload=function()
{
var oC=document.getElementById('content');
var oA=document.getElementById('aC');
if(oC.scrollHeight<=getStyle(oC,'height'))
oA.style.display='none';
else
oA.style.display='block';
oA.onclick=function()
{
if(oC.className=="exp")
{
this.innerHTML='收起';
oC.className='fold';
}
else
{
this.innerHTML='展开';
oC.className='exp';
}
}

}
function getStyle(obj,attr)
{
if(obj.currentStyle)
return parseFloat(obj.currentStyle[attr])
------解决方案--------------------
0;
return parseFloat(getComputedStyle(obj,0)[attr])
------解决方案--------------------
0;
}
</script>
</head>

<body>
<div class="div">
 <div class="exp" id="content">
 福建,在周朝为七闽地,春秋以后为闽越地。秦置闽中郡,中央政权始达于福建。汉初为闽越国疆域,闽越福建——安溪.中国茶都福建——安溪.中国茶都(4张)
9县。 福建,在周朝为七闽地,春秋以后为闽越地。秦置闽中郡,中央政权始达于福建。汉初为闽越国疆域,闽越福建——安溪.中国茶都福建——安溪.中国茶都(4张)
9县。 福建,在周朝为七闽地,春秋以后为闽越地。秦置闽中郡,中央政权始达于福建。汉初为闽越国疆域,闽越福建——安溪.中国茶都福建——安溪.中国茶都(4张)
9县。
 </div>
 <a href="javascript:;" id="aC">展开</a>
</div>
</body&g