function getYourString(s) { var res = ''; var length = s.length; for (var i = 0, j = 1; i '; } else { res += s[i]; } } ... ...
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));