faq 折叠效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript" type="text/javascript">
var curr=null;

function initFaq(){
var faq=document.getElementById("faq");
var hs=faq.getElementsByTagName("h5");
var ps=faq.getElementsByTagName("p");
for (var i=0;i<hs.length;i++){
hs[i].id='h5_syy_'+i;
ps[i].id=hs[i].id+'_x';

hs[i].onclick=function(){
if (curr!=null&&curr!=this.id)
document.getElementById(curr+"_x").style.display='none';
var s=document.getElementById(this.id+"_x").style;
s.display=((s.display=='none')?'':'none');
if (s.display!='none')
curr=this.id;
else
curr=null;
}
hs[i].style.cursor='pointer';
ps[i].style.display='none';

}
}
</script>
</head>
<body onload="initFaq()">
<ul id="faq">
<li>
<h5>问题1</h5>
<p>答:1略略略略略略略略略略略略略略略略略略略略略略略略略略</p>
</li>
<li>
<h5>问题2</h5>
<p>答:2略略略略略略略略略略略略略略略略略略略略略略略略略略</p>
</li>
<li>
<h5>问题3</h5>
<p>答:3略略略略略略略略略略略略略略略略略略略略略略略略略略</p>
</li>
<li>
<h5>问题4</h5>
<p>答:4略略略略略略略略略略略略略略略略略略略略略略略略略略</p>
</li>
</ul>
</body>
</html>

你可能感兴趣的:(FAQ)