簡體   English   中英

如何僅在文本區域的開頭刪除空白和換行符

[英]How to remove whitespace and new line, only at beginning of textarea

我只想在開始時刪除空格和換行。 我需要一些建議,我正在使用以下代碼。

var myTxtArea = document.getElementById('visionText');
myTxtArea.value = myTxtArea.value.replace(/^s|^n/g, '');

 alert(" \\n\\n I am a string \\n starting with whitespace and newline"); alert(" \\n\\n I am a string with no starting whitespace and newline".replace(/^\\s+/, "")); 

var reg = /^\s|\n/g;

var str = " asdfkadsf[xxxxx]bb";

var test = str.replace(reg,"") ;

也嘗試一下

" \n\n    I am a string  ".replace(/^\s+/,"");

好的,您將嘗試使用函數修剪,該函數從開頭和結尾刪除空白和換行

var myTxtArea = document.getElementById('visionText'); myTxtArea.value = myTxtArea.value.trim();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM