jquery 文字超出省略号,点击显示全部、收起
2018-01-22 18:09
447 查看
<!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>jquery 文字超出省略号,点击显示全部、收起</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="desc">
<ul>
<li>
<div class="branddesc">两句话深度开发几号上的佛牌维护佛文化的开户费收到了家很富是的开户费了色块大黄蜂评委会分是开将恢复时来得快积分还圣诞快乐抵抗力金凤凰收到了开间房</div>
</li>
<li>
<div class="branddesc">复合弓放假光华科技个我快让他也未发生的分数线从V型从v错把女女过一会就返回二过水电费三的丰盛的v格式规范换个环境感觉感觉吃吧许不舒服个的非国有etymology返回返回</div>
</li>
</ul>
</div>
<script>
(function($){
$.fn.moreText = function(options){
var defaults = {
maxLength:50,
mainCell:".branddesc",
openBtn:'显示全部',
closeBtn:'收起'
}
return this.each(function() {
var _this = $(this);
var opts = $.extend({},defaults,options);
var maxLength = opts.maxLength;
var TextBox = $(opts.mainCell,_this);
var openBtn = opts.openBtn;
var closeBtn = opts.closeBtn;
var countText = TextBox.html();
var newHtml = '';
if(countText.length > maxLength){
newHtml = countText.substring(0,maxLength)+'...<span class="more">'+openBtn+'</span>';
}else{
newHtml = countText;
}
TextBox.html(newHtml);
TextBox.on("click",".more",function(){
if($(this).text()==openBtn){
TextBox.html(countText+' <span class="more">'+closeBtn+'</span>');
}else{
TextBox.html(newHtml);
}
})
})
}
})(jQuery);
$(function(){
$(".desc ul li").moreText({
maxLength: 10, //默认最大显示字数,超过...
mainCell: '.branddesc' //文字容器
});
})
</script>
</body>
</html>
js代码
(function($){
$.fn.moreText = function(options){
var defaults = {
maxLength:50,
mainCell:".branddesc",
openBtn:'显示全部',
closeBtn:'收起'
}
return this.each(function() {
var _this = $(this);
var opts = $.extend({},defaults,options);
var maxLength = opts.maxLength;
var TextBox = $(opts.mainCell,_this);
var openBtn = opts.openBtn;
var closeBtn = opts.closeBtn;
var countText = TextBox.html();
var newHtml = '';
if(countText.length > maxLength){
newHtml = countText.substring(0,maxLength)+'...<span class="more">'+openBtn+'</span>';
}else{
newHtml = countText;
}
TextBox.html(newHtml);
TextBox.on("click",".more",function(){
if($(this).text()==openBtn){
TextBox.html(countText+' <span class="more">'+closeBtn+'</span>');
}else{
TextBox.html(newHtml);
}
})
})
}
})(jQuery);
$(function(){
//调用
$(".desc ul li").moreText({
maxLength: 10, //默认最大显示字数,超过...
mainCell: '.branddesc' //文字容器
});
})
原文:http://www.qdfuns.com/notes/27580/c87777d696752ecf0926297957f71da9.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery 文字超出省略号,点击显示全部、收起</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="desc">
<ul>
<li>
<div class="branddesc">两句话深度开发几号上的佛牌维护佛文化的开户费收到了家很富是的开户费了色块大黄蜂评委会分是开将恢复时来得快积分还圣诞快乐抵抗力金凤凰收到了开间房</div>
</li>
<li>
<div class="branddesc">复合弓放假光华科技个我快让他也未发生的分数线从V型从v错把女女过一会就返回二过水电费三的丰盛的v格式规范换个环境感觉感觉吃吧许不舒服个的非国有etymology返回返回</div>
</li>
</ul>
</div>
<script>
(function($){
$.fn.moreText = function(options){
var defaults = {
maxLength:50,
mainCell:".branddesc",
openBtn:'显示全部',
closeBtn:'收起'
}
return this.each(function() {
var _this = $(this);
var opts = $.extend({},defaults,options);
var maxLength = opts.maxLength;
var TextBox = $(opts.mainCell,_this);
var openBtn = opts.openBtn;
var closeBtn = opts.closeBtn;
var countText = TextBox.html();
var newHtml = '';
if(countText.length > maxLength){
newHtml = countText.substring(0,maxLength)+'...<span class="more">'+openBtn+'</span>';
}else{
newHtml = countText;
}
TextBox.html(newHtml);
TextBox.on("click",".more",function(){
if($(this).text()==openBtn){
TextBox.html(countText+' <span class="more">'+closeBtn+'</span>');
}else{
TextBox.html(newHtml);
}
})
})
}
})(jQuery);
$(function(){
$(".desc ul li").moreText({
maxLength: 10, //默认最大显示字数,超过...
mainCell: '.branddesc' //文字容器
});
})
</script>
</body>
</html>
js代码
(function($){
$.fn.moreText = function(options){
var defaults = {
maxLength:50,
mainCell:".branddesc",
openBtn:'显示全部',
closeBtn:'收起'
}
return this.each(function() {
var _this = $(this);
var opts = $.extend({},defaults,options);
var maxLength = opts.maxLength;
var TextBox = $(opts.mainCell,_this);
var openBtn = opts.openBtn;
var closeBtn = opts.closeBtn;
var countText = TextBox.html();
var newHtml = '';
if(countText.length > maxLength){
newHtml = countText.substring(0,maxLength)+'...<span class="more">'+openBtn+'</span>';
}else{
newHtml = countText;
}
TextBox.html(newHtml);
TextBox.on("click",".more",function(){
if($(this).text()==openBtn){
TextBox.html(countText+' <span class="more">'+closeBtn+'</span>');
}else{
TextBox.html(newHtml);
}
})
})
}
})(jQuery);
$(function(){
//调用
$(".desc ul li").moreText({
maxLength: 10, //默认最大显示字数,超过...
mainCell: '.branddesc' //文字容器
});
})
原文:http://www.qdfuns.com/notes/27580/c87777d696752ecf0926297957f71da9.html
相关文章推荐
- 如何实现js展开收起(折叠)效果呢?例如:一段内容过长了,我限制他显示为20个字内,但是超出了20的就先用省略号代替,然后后面添加一个展开,点击展开后就显示所有的内容,这时候展开按钮就变成了 折叠按钮
- jQuery 实现全部到精简的转换 点击“显示全部品牌按钮”显示到第二幅图,个别文字高亮显示,并且“显示全部品牌”按钮文字变为“精简显示品牌”并且向上向下箭头改变,用JQuery实现本功能。
- jquery 实现超出部分隐藏,鼠标移动上显示全部文字 .
- jquery 实现超出部分隐藏,鼠标移动上显示全部文字
- JS/jQuery实现默认显示部分文字点击按钮显示全部内容
- jquery 实现超出部分隐藏,鼠标移动上显示全部文字
- jquery 实现超出部分隐藏,鼠标移动上显示全部文字
- html动态添加需要显示的内容/文字过多,超出部分以省略号显示,鼠标移入时全部显示
- JS/jQuery实现默认显示部分文字点击按钮显示全部内容
- 超出div宽度范围的文字进行省略号省略,在鼠标移上去以后显示完整的内容
- Android TextView内容过长加省略号,点击显示全部内容
- 【阅读】《Head First jQuery》第二章——选择器与方法(一个点击图片页面显示文字的小例子)
- CSS控制文字只显示一行,超出部分显示省略号
- html + CSS实现文字超出长度隐藏,显示省略号
- css设置文字超出部分显示省略号。。。
- 使用text-overflow:ellipsis实现文字超出用省略号显示
- jQuery常用插件(一)当文字内容太多超出显示区时,用三个点代替显示
- CSS3文字超出两行或者多行显示省略号-webkit-line-clamp属性
- 文字超出元素范围时自动显示省略号
- table td 文字超出显示省略号