Wrap Text inside fixed Div with css or javascript?

后端 未结 2 1077
情歌与酒
情歌与酒 2020-12-11 08:17

I have tinymce editor(textarea) and one div. Whenever I type inside the text editor, it shows at the preview div which is (200px) in real time which is looks alike stackover

2条回答
  •  时光说笑
    2020-12-11 09:11

    function GetWrapedText(text, maxlength) {    
        var resultText = [""];
        var len = text.length;    
        if (maxlength >= len) {
            return text;
        }
        else {
            var totalStrCount = parseInt(len / maxlength);
            if (len % maxlength != 0) {
                totalStrCount++
            }
    
            for (var i = 0; i < totalStrCount; i++) {
                if (i == totalStrCount - 1) {
                    resultText.push(text);
                }
                else {
                    var strPiece = text.substring(0, maxlength - 1);
                    resultText.push(strPiece);
                    resultText.push("
    "); text = text.substring(maxlength - 1, text.length); } } } return resultText.join(""); }

提交回复
热议问题