我想删除不必要的空间,并在textarea的分隔行中写入内容。
实施例
ABC
ABCDE
ABD
将其转换为:
ABC
ABCDE
ABD
答案 0 :(得分:1)
你需要做两件事:
CODE:
var content = myTextArea.value;
//Split into lines
var lines = content.split( /\r?\n/ );
//Your new content
var newContent = "";
//Loop through all lines
for ( var i = 0; i < lines.length; i++ )
{
//Trim it first
var line = lines[ i ].trim();
//Empty line, remove it
if ( line === "" ) continue;
//Add to new content
newContent += line + "\n";
}
//Save to text area
myTextArea.value = newContent;