运用正则表达式去左右空格

var oBtn = document.getElementById(“btn”);
var oTxt = document.getElementById(“txt”);
oBtn.onclick = function(){
var str = oTxt.value;
//var re = /^\s+/g;
//var re = /\s+KaTeX parse error: Expected group after '^' at position 20: … var re = /(^̲\s+|\s+)/g;
str = str.replace(re,’’);
alert(’-’ + str + ‘-’)
}

上一篇:JavaScript添加事件的三种方式(鼠标点击事件)


下一篇:4.2 JSR303 & 松散绑定