我想删除行首和行尾的多余空格,但保留换行符,这是我的尝试。删除空格但留下换行符在文本区域中使用JS或jQuery
function removeSpaces(string) {
return string.split(' ').join('');
}
<center>
\t <form action="getid.php" method="post">
\t \t <textarea name="items" id="itemNames" cols="100" rows="10" onblur="this.value=removeSpaces(this.value);"></textarea><br />
\t \t <input type="submit" value="Get dem IDs">
\t \t <input type="button" id="remove" value="Remove extra spaces">
\t </form>
</center>
但是,相反,它是删除所有空格和 '\ n'
不知道为什么你的Java标记。将删除。 –
我删除了Java标记,因为这个问题与Java无关。 –
想要标记Javascript,抱歉。 – user1114748