- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试找出一种方法来缩短可能包含链接的文本正文。
<div class="bio">
Banjo my soundcloud is <a href="http://soundcloud.com/username">http://soundcloud.com/username</a>
Echo Park kale chips blog, cred pitchfork keffiyeh mixtape tumblr photo booth artisan helvetica
meggings fashion axe roof party. Aesthetic biodiesel direct trade butcher, iPhone occupy before
they sold out trust fund mumblecore cornhole food truck DIY narwhal freegan. Salvia try-hard
freegan, Brooklyn Marfa craft beer fanny pack dreamcatcher High Life irony sriracha. Mumblecore
Terry Richardson ethnic, pop-up tattooed sartorial 3 wolf moon banjo biodiesel church-key semiotics
polaroid Etsy Schlitz hashtag. Wes Anderson gluten-free lomo brunch, raw denim plaid Schlitz salvia.
</div>
我最初尝试通过 chop 字符数来缩短文本正文,之后我会插入一个“更多”链接,将其余文本放在一个范围内,然后隐藏该范围直到“更多”链接被点击。但是,如果用户决定将链接放在错误的位置,插入“更多”链接会破坏用户放置的 anchor 标签。
这是我为这个问题找到的解决方案,不起作用:http://www.bookofzeus.com/articles/dynamically-shortened-text-using-jquery/
缩短可能包含 anchor 标记的文本正文的好方法是什么?
最佳答案
你是对的,那个 jquery 演示代码没有工作,但是这个演示可以。我不得不解决一些问题,但这里有一个你可以达到顶峰的 fiddle 。我也用了你的文本信息。
$(document).ready(function() {
var orgContent = $('.bio').html();
var txtContent = $('.bio').text().substr(0, 50) + '... <a id="morelink">more</a>';
$('.bio').html(txtContent);
$("body").on("click", '#morelink', function(){
$('.bio').html(orgContent);
$('<a id="lesslink"> less</a>').appendTo('.bio');
});
$("body").on("click", '#lesslink', function(){
$('.bio').html(txtContent);
});
});
关于javascript - 试图缩短可能包含链接的文本正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16824778/
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How do short URLs services work? 我经常看到来自 bitly.com 的缩短
if (args.join(" ").toLowerCase() === "are you" || args.join(" ").toLowerCase() === "are you doing")
学习Golang,想知道是否有更短的编写方法 if tiletype == 0 || tiletype == 2 { levelmap[pass
sum_num = 0 for human in humans: sum_num += human.limbs return sum_num 假设对象 human 具有属性 limbs ,如下
我想问一下是否有一种方法可以像在 MSSQL 中那样缩短这个条件,因为我也有类似的条件。 if(docType == "PO" || docType == "II" || docType == "IA
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
我在单页上有一些 15-20 个 Highcharts (使用 slider ,每张幻灯片 1-2 个图表)、一些条形图、一些柱形图、一些饼图,具有不同的显示选项。我使用的是在我的闭包内有多种方法,其
几周前,我在下拉菜单的一些代码上得到了一些帮助,但我想知道是否可以使代码更短,因为下面显示的当前代码相当大,任何帮助都会很棒。 $(document).ready(function(){ $(
这里是新的。我只是想知道是否有可能使这个 if 语句更短且冗余更少。 if (!a && b) { if (c == d && e > 0) { return;
我有这个代码。 c = getch() if c == "r":
我有几行代码用于迭代列表中的字典,我想缩短它。它按原样完美运行,但似乎代码太多,我正在尝试了解如何在 Python 中(或一般情况下)保持代码高效。 for d in dev['devices']:
如果代码如下,如何缩短 if 语句? $a = null; $b = "foo"; if ((empty($a) && !empty($b)) || (!empty($a) && empty($b))
我需要计算应用的每日独立用户数。 我可以唯一识别用户的唯一方法是通过他们的 UUID(这是外部提供的,所以我不得不使用它)。 我知道我的每日用户数是几百万。 我想在 Redis 中使用一个 bitse
载体 a和 b可以使用 toString(width = 10) 缩短在 Base R 中导致以 .... 结尾的较短向量 但是,我想知道如何使缩短的向量以 ..., last vector elem
是否有缩短 HTML 页面的库(最好是 Python 库)?我的意思是它会生成一个可能更小的(就字符数而言,包括换行符 Silly example 可以改成: Silly example
如何缩短这段 CSS 的代码?当它在移动 View 中时,它将隐藏表格的某些列。我的表有 137 列,我只想查看 5 列。 @media only screen and (max-width: 800
我所拥有的是主目录中的文件路径,我希望将其处理为包含“~”的缩短路径。 例如,我的输入可能是:"/home/username/test"或 /home/./username/test或 /home/.
我们为文档生成一个 GUID,并且需要将该 GUID 包含在 C40 编码的条码(Type 29 2D)中,并且具有以下限制。 最长可达 25 个字符只能使用大写字母数字字符,不能使用特殊字符。 我曾
这个问题已经有答案了: Ternary operators in JavaScript without an "else" (13 个回答) 已关闭 4 年前。 我一直使用这样的三元表达式,但我不喜欢
首先,我想确保我知道这样一个事实:重新哈希是一个明智的话题。不过,我想听听您的一些意见,以及您会采取什么方法。 我正在构建一个分布式应用程序,其中节点远程创建由 UUID 标识的实体。最终,所有实体应
我是一名优秀的程序员,十分优秀!