zoukankan      html  css  js  c++  java
  • js 展开/收起效果

    <!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>
    *{ font-size:14px;}
    .ico{ background:url(http://mat1.gtimg.com/www/icon/favicon2.ico) no-repeat center ; cursor:pointer; display:inline-block; text-indent:-999px; width:28px;}
    .closeTag{background:#F60; cursor:pointer;}
    
    ul{ width:500px; border:1px solid #FC6; list-style:none;}
    ul li{ margin:15px; line-height:30px; text-indent:30px;}
    
    </style>
    </head>
    <script>
        //toggle点评
        function toggleWords(obj)
        {
            var childs = obj.parentNode.childNodes;
            var longstr,shortstr,textnode;
            
            for(var i=0,len=childs.length;i<len;i++)
            {http://www.baidu.com/img/bdlogo.gif
                //需要操作的文本节点
                if(childs[i].nodeType == 3 && textnode == undefined)
                {
                    textnode = childs[i];
                }
                //详细信息
                if(childs[i].nodeType == 1 && childs[i].name == 'long')
                {
                    longstr = childs[i].value;
                }
                
                //简短信息
                if(childs[i].nodeType == 1 && childs[i].name == 'short')
                {
                    shortstr = childs[i].value;
                }
            }
            
            if(longstr == undefined || shortstr == undefined || textnode == undefined)
            {
                return ;
            }
    
            if(obj.innerHTML == '展开')
            {
                textnode.nodeValue = longstr;
                obj.innerHTML = '收起';
                obj.className = 'ico closeTag';
            }else{
                textnode.nodeValue = shortstr;
                obj.innerHTML = '展开';
                obj.className = 'ico';
            }
        }
    </script>
    
    <body>
    <dd >
    <ul>
        <li>
            腾讯娱乐讯 2012年第一届"两天微电影大赛"完美收官...<span class="ico" onclick="toggleWords(this); return false;">展开</span>
            <input name="long" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官后,时隔一年, 在中国电视艺术家协会支持下,上海戏剧学院和新西兰华语媒体再度联合主办的&quot;2013年第二届两天微电影大赛&quot; 近日在上海正式启动,此次他们另辟蹊径,面对海内外所有电影爱好者,旨在开启微电影时代的全民化。" />
            <input name="short" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官..." />
        </li>
        <li>
            腾讯娱乐讯 2012年第一届"两天微电影大赛"完美收官...<span class="ico" onclick="toggleWords(this); return false;">展开</span>
            <input name="long" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官后,时隔一年, 在中国电视艺术家协会支持下,上海戏剧学院和新西兰华语媒体再度联合主办的&quot;2013年第二届两天微电影大赛&quot; 近日在上海正式启动,此次他们另辟蹊径,面对海内外所有电影爱好者,旨在开启微电影时代的全民化。" />
            <input name="short" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官..." />
        </li> 
        <li>
            腾讯娱乐讯 2012年第一届"两天微电影大赛"完美收官...<span class="ico" onclick="toggleWords(this); return false;">展开</span>
            <input name="long" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官后,时隔一年, 在中国电视艺术家协会支持下,上海戏剧学院和新西兰华语媒体再度联合主办的&quot;2013年第二届两天微电影大赛&quot; 近日在上海正式启动,此次他们另辟蹊径,面对海内外所有电影爱好者,旨在开启微电影时代的全民化。" />
            <input name="short" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官..." />
        </li>
        <li>
            腾讯娱乐讯 2012年第一届"两天微电影大赛"完美收官...<span class="ico" onclick="toggleWords(this); return false;">展开</span>
            <input name="long" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官后,时隔一年, 在中国电视艺术家协会支持下,上海戏剧学院和新西兰华语媒体再度联合主办的&quot;2013年第二届两天微电影大赛&quot; 近日在上海正式启动,此次他们另辟蹊径,面对海内外所有电影爱好者,旨在开启微电影时代的全民化。" />
            <input name="short" type="hidden" value="腾讯娱乐讯 2012年第一届&quot;两天微电影大赛&quot;完美收官..." />
        </li>     
    </ul>
    </dd>
    </body>
    </html>

    效果图:

      

  • 相关阅读:
    再谈CLR:值类型按照引用传递(以及与装箱拆箱的区别)
    Silverlight的跨站策略和跨站策略文件
    再谈CLR:MSCorEE.dll文件的奥秘
    再谈CLR:如何通过代码获取程序集所引用的程序集信息
    再谈方法的动态调用
    Silverlight隔离存储(续)
    支持取消操作和暂停操作的Backgroundworker
    单件模式(Singleton)和锁定(lock)
    在SharePoint服务器中执行备份和还原
    如何:将 TraceSource 和筛选器与跟踪侦听器一起使用(转载)
  • 原文地址:https://www.cnblogs.com/siqi/p/3165366.html
Copyright © 2011-2022 走看看