gpt4 book ai didi

javascript - 用 Javascript 将长句子分成多行

转载 作者:行者123 更新时间:2023-12-03 10:38:19 26 4
gpt4 key购买 nike

我的 mysql 字段中有一个长句子,在我的 jquery 表中文本显示如下:

In the aftermath of her sudden Vancouver celebrity, she appeared as the cover girl on Playboy magazine's October 1989 issue. At that point she decided to live in Los Angeles to further pursue her modeling career. Playboy subsequently chose her as Playmate of the Month in their February 1990 issue, in which she appeared in the centerfold photo.

exceeds limit

我想在 12 个单词后将长句子分成多行(示例)

In the aftermath of her sudden Vancouver celebrity, she appeared as the
cover girl on Playboy magazine's October 1989 issue. At that point she
decided to live in Los Angeles to further pursue her modeling career. Playboy
subsequently chose her as Playmate of the Month in their February 1990
issue, in which she appeared in the centerfold photo.

我可以使用什么 JavaScript 代码?

最佳答案

您好,这是我使用 JavaScript 的代码,请查看演示。如果您有问题,请告诉我。我除以 12

var paragraph = "In the aftermath of her sudden Vancouver celebrity, she appeared as the cover girl on Playboy magazine's October 1989 issue. At that point she decided to live in Los Angeles to further pursue her modeling career. Playboy subsequently chose her as Playmate of the Month in their February 1990 issue, in which she appeared in the centerfold photo. Heloo Im van testing this code";

$(function(){
var data = paragraph.split(' ');
var x=0,y=0,iterator=12;
var xarray = data.length;
for(var i = iterator;i < xarray; i +=iterator){
$('#container').append(paragraph.split(/\s+/).slice(x,i).join(" ")+"<br />");
y = xarray-i;
x = i;
if(y<iterator){
$('#container').append(paragraph.split(/\s+/).slice(x,i+y).join(" ")+"<br />");
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container"></div>

关于javascript - 用 Javascript 将长句子分成多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28898634/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com