js 每到达5次换一行

    function getYourString(s) {
        var res = '';
        var length = s.length;
        for (var i = 0, j = 1; i < length; i++, j++) {
            //每到达5次,添加一个换行标签
            if (j && j % 6 == 0) {
                res += '<br />';
            } else {
                res += s[i];
            }
        }
        return res;
    }
    var test = '123456534545435435435';
    document.write(getYourString(test));

  

posted @ 2018-03-22 18:03  abcByme  阅读(2138)  评论(0编辑  收藏  举报