var wordWrap = function(bigString, m, b, c){
var i, j, s, r = bigString.split("\n");
if(m > 0) for(i in r){
for(s = r[i], r[i] = ""; s.length > m;
j = c ? m : (j = s.substr(0, m).match(/\S*$/)).input.length - j[0].length
|| m,
r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? b : "")
);
r[i] += s;
}
return r.join("\n");
};
alert(wordWrap("My world is biiiiiiiiiiiiig", 10, "\n", true));
alert(wordWrap("My world is biiiiiiiiiiiiig", 10, "\n", false));
1 則留言:
非常好!
張貼留言