jQuery之后的文本格式问题 [英] Issues with text formatting after jQuery
问题描述
我在这里使用了代码形式:在另一个div中用html覆盖文本-使文本在新区但是,现在我的文本存在格式问题. 每个段落的第一个单词都以某种方式后跟换行符.
I have used code form here: Overflowed text with html in another div - to get text to flow over in a new div. However, now I have formatting issues with the text. The first word of every paragraph is somehow followed by a line-break.
您可以在此处看到示例: http://jsfiddle.net/hm2yfw61/9/
You can see an example here: http://jsfiddle.net/hm2yfw61/9/
var currentCol = $('.box:first');
var text = currentCol.html();
currentCol.html('');
text = text.replace(/ (?![^<>]*>)/gi, '%^%');
var wordArray = text.split('%^%');
$.fn.hasOverflow = function () {
var div = document.getElementById($(this).attr('id'));
return div.scrollHeight > div.clientHeight;
};
for (var x = 0; x < wordArray.length; x++) {
var word = wordArray[x];
currentCol.append(word + ' ');
if (currentCol.hasOverflow()) {
currentCol = currentCol.next('.box');
}
}
有人知道我该如何解决吗?
Does anyone know how I can fix this?
谢谢.
----- UPDATE:我已经使用可能会遇到类似问题的其他人参考中建议的可行解决方案对jsfiddle进行了更新------
-----UPDATE: I've updated the jsfiddle with the working solutions suggested in reference for others who may face similar problems ------
推荐答案
这可能有点hacky,但是请尝试以下操作:
This might be a bit hacky, but try the following:
- 添加以下CSS规则
.box > p:first {
display: none;
}
.box > p:first {
display: none;
}
-
在
.box > p
标签中每个字符串的开头添加"nbsp;"(包括空格).
Add "nbsp; " (including the space) at the beginning of each string in
.box > p
tags.
<p> Jumo handango
这篇关于jQuery之后的文本格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!