function FormatText(names)
{
var texts = document.getElementById(names)
var cbody = texts.value;
cbody = autoFormat(cbody);
texts.value=cbody;
}
function ltrim(s){
return s.replace( /^[" "|" "]*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /[" "|" "]*$/, "");
}
//左右空格;
function trim(s){
return rtrim(ltrim(s));
}
//自动排版
function autoFormat(key){
var c=key;
var cc="";
if(c.indexOf("\r\n")>-1){
var brs=c.split("\r\n");
for(var i=0;i<brs.length;i++){
//开头加入全角空格
cc=cc+" "+" "+trim(brs[i])+"\r\n";
}
return cc;
}
}
转载于:https://blog.51cto.com/userjob/559956