展开与收缩的JS代码问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 10:14:33
下面这段代码默认是展开状态,帮我改成默认是收缩状态.并且要能够正常使用. 有其它可以实现这个功能的代码也行啊.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>runcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<script type="text/javascript">
var mh = 30;//最小高度
var step = 5;//每次变化的px量
var ms = 10;//每隔多久循环一次
function toggle(o){
if (!o.tid)o.tid = "_" + Math.random() * 100;
if (!window.toggler)window.toggler = {};
if (!window.toggler[o.tid]){
window.toggler[o.tid]={
obj:o,
maxHeight:o.offsetHeight,

<div class="xx"><h5 onclick="toggle(this.parentNode)">点击我看"伸缩效果"</h5>
改成
<div class="xx" id="aaa"><h5 onclick="toggle(this.parentNode)">点击我看"伸缩效果"</h5>

加个
window.onload=function(){
toggle(document.getElementById("aaa"))
}

似乎只能这样哦...因为按你上面的原有的收缩方法..div的高度是要页面加载完后..才能得到offsetHeight.
不然似乎改动要大点了.