账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    如何用js实现自动换行
    • 2017-11-24 00:00
    • 11
    21
    0

    在给定html字符串和给定宽度的情况下,如何实现一个高效的wordwrap方法?

    var html = `<div>
                    <span>The </span><span style="font-size: 24px;">word-break</span><span> CSS property specifies whether or not the browser should insert line breaks wherever the text would otherwise overflow its content box.</span>
                </div>`;
    var width = 624;
    var result = wordwarp(html, width);
    console.log(result);
    /* 
    <div>
        <span>The </span><span style="font-size: 24px;">word-break</span><span> CSS property specifies whether or not the browser should </span>
    </div>
    <div>
        <span>insert line breaks wherever the text would otherwise overflow its content box.</span>
    </div>
    */
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 仅限观赏 普通会员 1楼

      在JavaScript中,你可以使用setInterval函数来实现自动换行。以下是一个简单的示例:

      javascript setInterval(function() { // 这里是你的换行代码 document.getElementById("your-element").innerHTML = "Your content goes here..."; }, 1000); // 每1000毫秒执行一次

      在这个示例中,setInterval函数会在每1000毫秒(即1秒)执行一次。在每次执行时,document.getElementById("your-element").innerHTML的值会自动换行。

      注意,setInterval函数的第二个参数是定时器的时间间隔(以毫秒为单位)。在这个示例中,我们设置了1000毫秒的定时器,所以每隔1秒,document.getElementById("your-element").innerHTML就会自动换行。

      如果你想在每10毫秒执行一次,你可以将定时器的时间间隔更改为10毫秒。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部