gpt4 book ai didi

javascript - 如何使用 javascript 在行尾添加连字符

转载 作者:行者123 更新时间:2023-11-30 23:49:12 24 4
gpt4 key购买 nike

这是我的编码。使用css作为Hyphenate类的结果,结果显示在result1中。然而,我想要的是结果显示在result2中。另外,在 result1 中,当只有几个单词时,单词之间会出现很大的间隙,这真的很难看。现在有人如何解决这个问题吗?

--编辑问题--

我在这里问的是:我有一个用于输入的文本区域和一个用于结果的 div 标签。每当有一个单词到达右边界时,该单词就会换成新行,但是,目标就像结果 2 所示的那样。希望现在任何人都能理解。谢谢。

Div 标签的宽度=170px

.hyphenate{ 
text-wrap: suppress;
word-break: break-all;
word-wrap: break-word;
white-space: -moz-pre-wrap;
white-space: pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-line;
width:170px;
text-align:justify;
}

-

<script type="text/javascript">
function copyIt() {
var x = document.getElementById("textarea").value;
document.getElementById("result1").innerHTML = x;
}
</script>

-

<table border=2 width="160"> 
<tr>
<td colspan=2>
<h1>Hyphenator Tester</h1>
</td>
</tr>
<tr>
<td width="160" valign="top">
<textarea id="textarea" rows=5 cols=20 onkeyup="copyIt()">
This is the preview of something What
</textarea>
<br><br>Result:<br>
<div id="result1" class="hyphenate">
This is the preview of something what I've wrote earlier
</div>
<br>Result wanted:<br>
<div id="result2" class="hyphenate">
This is the preview of some- thing what I've wrote earlier
</div>
</td>
</tr>
</table>

最佳答案

尝试Hyphenator.js .

关于javascript - 如何使用 javascript 在行尾添加连字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1919676/

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