我必须使用专有的cms博客,该博客会将其作为包含
的“摘要标记”这是摘要标记当前在页面上呈现的方式:
<p>Content goes here....<a href="example.htm">Click here to read more.</a></p>
<p>More content goes here....<a href="anothertest.htm">Click here to read more.</a></p>
<p>Content goes here....<a href="helloworld.htm">Click here to read more.</a></p>
与此同时,我想用一些jquery控制摘要标记,所以我不仅限于它的刚性显示:
ellipsis
class
后添加href
,因此不会更新页面上的其他链接。这将是非常理想的预期结果。
<p>Content goes here.<a href="example.htm" class="readmore">Click here to read more.</a></p>
<p>More content goes here.<a href="anothertest.htm" class="readmore">Click here to read more.</a>
<p>Content goes here.<a href="helloworld.htm" class="readmore">Click here to read more.</a>
非常感谢您的帮助!
这就是我得到的,我知道这很糟糕
$("p").html("...").remove:after.attr(".readmore").attr("href"));
答案 0 :(得分:1)
$('p').each(function () {
var textNode = $(this).find('a:last-child').addClass('readmore')[0].previousSibling;
textNode.textContent = textNode.textContent.replace(/\.{3}\s*$/, '');
});