如何用div替换自定义PAGEBREAK标记

时间:2012-08-07 04:00:01

标签: jquery html replace

我有这份文件,例如:

This is the first line
<br> 
This is the second line 
<br>
This is the third line

现在我想删除<br>并格式化文字,如下所示

    <DIV ID=PAGINATION-CONTENT>
        This is the first line
    </DIV>
    <DIV ID=PAGINATION-CONTENT>
        This is the second line 
    </DIV>
    <DIV ID=PAGINATION-CONTENT>
       This is the third line
    </DIV>

如何通过使用jquery来实现?

2 个答案:

答案 0 :(得分:1)

这样的东西?我使用classes因为ID必须是唯一的!

<p>
  This is the first line
  <br>
  This is the second line
  <br>
  This is the third line
</p>

var lines = $('p').html().split('<br>')
var divs = '';
$.each(lines, function(i, line) {
    divs += '<div class="PAGINATION-CONTENT">'+line+'</div>';
})

$('p').html(divs)  

DEMO

答案 1 :(得分:0)

您可能正在寻找page-break-beforepage-break-after css规则。

假设您正在谈论实际的分页符(即打印时)。如果没有,那么你的问题就不清楚了。