问问题
898 次
2 回答
3
这是我的解决方案:
function makeParagraphs(text){
return '<p>' + text.replace(/(.{200}[^\.]*)(\.)+/g, '</p>$1.<p>') + '</p>';
}
您可以在此jsfiddle的示例中对其进行测试。
于 2014-01-23T15:15:24.170 回答
2
您可以抓取文本并循环播放所有内容,直到结束。这是一个小提琴演示
$(function () {
$('button').on('click', function () {
var theText = $('textarea').val();
var i = 200;
while (theText.length > 200) {
console.log('looping');
while (theText.charAt(i) !== '.') {
i++;
}
console.log(i);
$("#text_land").append("<p>" + theText.substring(0, i+1) + "</p>");
theText = theText.substring(i+1);
i = 200;
}
$('#text_land').append("<p>" + theText + "</p>");
})
})
于 2014-01-23T15:13:58.607 回答