原文发布时间为:2009-11-15 —— 来源于本人的百度文章 [由搬家工具导入]

<!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=gb2312" />
<title>无标题文档</title>
</head>

<body>
<div id="divS" style="border:1px solid #f0f0f0;background-color:#ccc;padding:4px;margin:10px">
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
<p>测试</p>
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
</div>
<p>
<script type="text/javascript"><!--
doShrink(document.getElementById('divS'),60);
function doShrink(oshrink,maxHeight){  
    if(oshrink){  
        var oH = (oshrink.clientHeight||oshrink.offsetHeight);  
        if(oH>maxHeight){  
            var linka = document.createElement("a");  
            var div = document.createElement("div");     
            div.innerHTML = "……<br />"
            text = document.createTextNode("[点击查看更多内容]");
            linka.href = "javascript:void(0)";  
            linka.onclick = function(e) { shrinkShow(this); }  
            linka.appendChild(text);  
            div.appendChild(linka);
            var onext = oshrink.nextSibling;  
            if(onext)  
                oshrink.parentNode.insertBefore(div,onext);  
            else
                oshrink.parentNode.appendChild(div);  
            //过滤较长的内容  
            oshrink.srcHeight = oH;  
            oshrink.style.cssText ="overflow-y: hidden; max-height: "+maxHeight+"px; *_height: "+maxHeight+"px; ";  
        }  
    }  
}

function remove(o){
if(o && o.parentNode)o.parentNode.removeChild(o);
}

/* 第一种,具有展开效果 */
var shrinkInterval = false;  
function shrinkShow(obj) {  
    var omore = obj.parentNode;  
    var ohide = omore.previousSibling;  
    shrinkInterval = window.setInterval(function(){shrinkStep(ohide);},20);
remove(omore); //去除更多链接
}  

function shrinkStep(ohide){  
    var targetHeight = ohide.srcHeight;  
    var nowHeight = (ohide.clientHeight||ohide.offsetHeight);;  
    if(nowHeight < targetHeight){  
        ohide.style.height = nowHeight+20 + 'px';  
        ohide.style.maxHeight = nowHeight+20 + 'px';  
    }else{  
        if(shrinkInterval){  
            window.clearInterval(shrinkInterval);  
            shrinkInterval = false;  
        }  
    }  
}

/* 第二种,没有展开效果 */

/*
function shrinkShow(obj) {  
    var omore = obj.parentNode;  
    var ohide = omore.previousSibling;  
    ohide.style.height = ohide.srcHeight + 'px';  
    ohide.style.maxHeight = ohide.srcHeight + 'px';
remove(omore); //去除更多链接
}
*/

// --></script>
</p>
</body>
</html>

JavaScript文本收缩展开 showdetail的更多相关文章

  1. jQuery文本段落展开和折叠效果

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  2. JS 播放列表收缩展开

    下面要做实现的效果 收缩和展的功能 遵循网页布局,行为,结构,样式 分离 下面是html 结构代码: <div id="drop" class="down_list ...

  3. jQuery 收缩展开效果

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  4. jQuery 文本段落展开和折叠效果

    jQuery 文本段落展开和折叠效果 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" c ...

  5. javascript 文本框值变化触发事件

    javascript 文本框值变化触发事件jo.find(".price").bind('input onpropertychange', function () { me.cal ...

  6. C#使用splitContainer控件制作收缩展开面板

    C#使用splitContainer控件制作收缩展开面板 原创 2011年07月19日 17:18:02 标签: c# / object / 扩展 / 测试 15690         最近对Squi ...

  7. JS收缩展开效果

    // 收缩展开效果 $(document).ready(function () { $(".box h2").toggle(function () { $(this).next(& ...

  8. 多个div的多文本部分展开显示+关键字自动标注

    效果: 源码: <%@ page language="java" contentType="text/html; charset=utf-8" pageE ...

  9. JavaScript文本框焦点事件

    效果图如下: <!-- 当文本框获得焦点时候,如果文本框内容是 请输入搜索关键字 清空文本框,输入内容变黑色 --> <!-- 当文本框失去焦点时候,如果文本框无内容,则添加灰色的 ...

随机推荐

  1. Java - Java 中的三种 ClassLoader

    1.虚拟机类加载器(称为“bootstrap class loader”),它本身没有父类加载器,它负责加载虚拟机的内置类,由于它是用C.C++写的,所以Java无法拿到其class文件,返回的都是空 ...

  2. 【JAVA】apachehttpclient设置http1.0短链接

    HttpPost httpPost = new HttpPost(url);httpPost.setEntity(new StringEntity(text, ContentType.create(& ...

  3. BootStrap下拉框搜索功能

    <!DOCTYPE html> <html> <head> <title>jQuery bootstrap-select可搜索多选下拉列表插件-www. ...

  4. ZendFramework-2.4 源代码 - 关于MVC - View层 - 在模板内渲染子模板

    <?php // 方式一: // 1.在模板内直接编写如下内容即可 $viewModel = new ViewModel(); $viewModel->setTemplate('album ...

  5. 关于使用Java开发Mis系统

    如何使用Java开发一个小型的信息管理系统,首先我们应该知道要使用什么样的方法. 1.Java基础 2.JSP+Servlet+JavaBean JSP是服务器端的编程语言,见得比较多的是在一些网站上 ...

  6. windows下的命令

    1.cd 现在默认只能在当前盘符中改变目录,如果要改变盘符则需要多加一个/d命令. cd /d d:/git/springTest 2.chdir 显示当前目录名或改变当前目录. CHDIR [/D] ...

  7. Pre 自动换行和手动换行

    pre { white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre ...

  8. C#入门篇6-3:字符串操作 string的ToString() Split()和Copy()方法

    //ToString()方法 public static void OutPut() { //字符型转换 转为字符串 Console.WriteLine(.ToString("n" ...

  9. OpenStack之Glance源码简析

    Glance简介 OpenStack镜像服务器是一套虚拟机镜像发现.注册.检索. glance架构图: Glance源码结构: glance/api:主要负责接收响应镜像管理命令的Restful请求, ...

  10. 47.关于gradle的解疑

    Short Answer Gradle is a build system. Long Answer Before Android Studio you were using Eclipse for ...