gpt4 book ai didi

javascript - 在 Jquery 中输入文本

转载 作者:太空狗 更新时间:2023-10-29 14:53:26 26 4
gpt4 key购买 nike

伙计们,我想让我的输入文本变成两行。

这是我的 Demo

请检查这段代码

HTML

  <div id="container">

<div class="writer">Hi! This is a test text.
<br><br>
Can any one
Help me in this ?.</div>

</div>

Java 脚本

var txt = $('.writer').text();
var timeOut;
var txtLen = txt.length;
var char = 0;
$('.writer').text('|');
(function typeIt() {
var humanize = Math.round(Math.random() * (200 - 30)) + 30;
timeOut = setTimeout(function() {
char++;
var type = txt.substring(0, char);
$('.writer').text(type + '|');
typeIt();

if (char == txtLen) {
$('.writer').text($('.writer').text().slice(0, -1)); // remove the '|'
clearTimeout(timeOut);
}

}, humanize);
}());

最佳答案

您可以添加 white-space: pre-line;.writer 声明以换行,如下所示:

.writer {
font:bold 23px arial;
white-space: pre-line;
}

WORKING DEMO

16.6 White space: the 'white-space' property

pre-line This value directs user agents to collapse sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.

值得注意的是行前的值is supported in IE8+ .

关于javascript - 在 Jquery 中输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22554589/

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