发新话题
打印

关于“收起/展开”

关于“收起/展开”

HTML代码:
复制内容到剪贴板
代码:
<style type="text/css">
.headactions {
        float: right;
        line-height: 1em;
        padding: 10px 10px 0 0;
}

.headactions img {
        vertical-align: middle;
        cursor: pointer;
        padding: 0 5px;
}
</style>
<div class="mainbox forumlist">
<span class="headactions">
<img id="category_1_img" src="images/default/collapsed_no.gif" title="收起/展开" alt="收起/展开" onClick="toggle_collapse('category_1');" />
</span>
<h3><a href="index.php?gid=1">English</a></h3>
<table id="category_1" summary="category1" cellspacing="0" cellpadding="0" style="">
        <thead class="category">
                <tr>
                        <th>论坛</th>
                        <td class="nums">主题</td>
                        <td class="nums">帖数</td>
                        <td class="lastpost">最后发表</td>
                </tr>
        </thead>
</table>
</div>
JavaScript代码:
复制内容到剪贴板
代码:
<script language="javascript">
function $(id) {
        return document.getElementById(id);
}
function toggle_collapse(objname, noimg) {
        var obj = $(objname);
        obj.style.display = obj.style.display == '' ? 'none' : '';
        if(!noimg) {
                var img = $(objname + '_img');
                img.src = img.src.indexOf('_yes.gif') == -1 ? img.src.replace(/_no\.gif/, '_yes\.gif') : img.src.replace(/_yes\.gif/, '_no\.gif')
        }
         //这里写入cookie
        //var collapsed = getcookie('scd_collapse');
        //collapsed =  updatestring(collapsed, objname, !obj.style.display);
        //setcookie('scd_collapse', collapsed, (collapsed ? 86400 * 30 : -(86400 * 30 * 1000)));
}
</script>

TOP

补充getCookie, setCookie, updatestring

复制内容到剪贴板
代码:
function updatestring(str1, str2, clear) {
        str2 = '_' + str2 + '_';
        return clear ? str1.replace(str2, '') : (str1.indexOf(str2) == -1 ? str1 + str2 : str1);
}
function getcookie(name) {
        var cookie_start = document.cookie.indexOf(name);
        var cookie_end = document.cookie.indexOf(";", cookie_start);
        return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
        var expires = new Date();
        expires.setTime(expires.getTime() + seconds);
        document.cookie = escape(cookieName) + '=' + escape(cookieValue)
                + (expires ? '; expires=' + expires.toGMTString() : '')
                + (path ? '; path=' + path : '/')
                + (domain ? '; domain=' + domain : '')
                + (secure ? '; secure' : '');
}

TOP

他的这种html代码写法也是很值得学习的。

TOP

假发

提示: 作者被禁止或删除 内容自动屏蔽

TOP