jquery - 更新所有div元素的内部内容

标签 jquery

我有一个 Div,高度为 300px,宽度为 300px

我想在 Div 中放入一些文本,所以我想检查文本数量 比这个 div 区域更大,创建另一个 Div 标签并在其中放置剩余文本。 这可能吗?

已编辑

或者也许是这样的: 我如何将(例如)此文本转换为某些 Div 300*300:

A fractal is a mathematical set that has a fractal dimension that usually exceeds its topological dimension[1] and may fall between the integers.[2] Fractals are typically self-similar patterns, where self-similar means they are "the same from near as from far"[3] Fractals may be exactly the same at every scale, or as illustrated in Figure 1, they may be nearly the same at different scales.[2][4][5][6] The definition of fractal goes beyond self-similarity per se to exclude trivial self-similarity and include the idea of a detailed pattern repeating itself.[2]:166; 18[4][7]

As mathematical equations, fractals are usually nowhere differentiable, which means that they cannot be measured in traditional ways.[2][6][8] An infinite fractal curve can be perceived of as winding through space differently from an ordinary line, still being a 1-dimensional line yet having a fractal dimension indicating it also resembles a surface.[1]:48[2]:15

The mathematical roots of the idea of fractals have been traced through a formal path of published works, starting in the 17th century with notions of recursion, then moving through increasingly rigorous mathematical treatment of the concept to the study of continuous but not differentiable functions in the 19th century, and on to the coining of the word fractal in the 20th century with a subsequent burgeoning of interest in fractals and computer-based modelling in the 21st century.[9][10] The term "fractal" was first used by mathematician Benoît Mandelbrot in 1975. Mandelbrot based it on the Latin frāctus meaning "broken" or "fractured", and used it to extend the concept of theoretical fractional dimensions to geometric patterns in nature.[2]:405[7]

结果一定是这样的:

enter image description here

最佳答案

尝试如下操作:

var str = "This is a very long string. You don't know exactly how much width you will need for it to be displayed";
var ar = str.split(" ");
var index = 0;
var $test = $("#test");

while($test.height() < 300){
    console.log($test.height());
 $test.html($test.html() +" "+ ar[index++]); 
    if(!ar[index]){break;}  
}

var fits = ar.splice(0,index-1);
$("#fixed").html(fits.join(" "));
$("#overflow").html(ar.join(" "));

这对您来说应该是一个很好的起点。

<强> Example

编辑:扩展示例

关于jquery - 更新所有div元素的内部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12564757/

相关文章:

jquery - 删除 URL 中的字符(如果找到),然后重定向 jQuery

javascript - JQuery 可排序嵌套可排序 div

javascript - 回调返回真/假

javascript - 跨浏览器禁用用户选择(Ctrl + A)

jquery - 在我的页面上显示 Google Analytics

javascript - "Array to string conversion error"尝试获取字段值时

jquery - 列表项中的 Css z 索引不起作用

javascript - jquery取消选择事件

jquery - “SQLSTATE[23000] : Integrity constraint violation: 1062 Duplicate entry

javascript - 使用 javascript 捕获更改事件的输入