html
<button type="button" id="qckbh" >清除空白换行</button>
<textarea cols="20" rows="10" id="kw"></textarea>
空白换行
function qckbh() { let input = document.getElementById("kw");
let text = input.value.replace(/\n{2,}/g, '\n');
input.value = text;
};
所有换行
function qcsyhh() {
let input = document.getElementById("kw");
let text = input.value;
text = text.replace(/(\r\n|\n|\r)/gm, "");
input.value = text;
};
空格和换行
-----
function qchhkg() {
let input = document.getElementById("kw");
let text = input.value.replace(/\s+/g, "");
input.value = text;
};
所有空格
function qckg() {if(document.getElementById("kw").value.indexOf(" ")>=0){
var str = document.getElementById("kw").value;
var reg1 = new RegExp(" ","g");
var a1 = str.replace(reg1,"");
document.getElementById('kw').value=a1;
}
else {
alert("没有空格");
}};