且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Javascript选择段落的最后一行

更新时间:2023-02-05 09:55:24

while you tagged jquery .. this is a jquery code .. but be sure to include jquery first

var parText = $('#wrapper p').text(); // get text of p
var parSplit = parText.split("\n"); // split text by \n
var lastLine = parSplit[parSplit.length-1]; // get last line
parText.replace(lastLine , ''); // replace last line with nothing
$('#wrapper p').append('<span>'+lastLine+'</span>'); // append the last line with `<span>lastline</span>` and give it a style you need

DEMO

another DEMO with slideDown effect

上一篇 : :mySQL :: 插入表,数据来自另一个表?下一篇 : 复制data.frame的每一行,并指定每一行的复制次数?

相关阅读

技术问答最新文章