<html>
<SCRIPT LANGUAGE="JavaScript">
<!--
// ALLTrim(), LRTrim() , Ltrim() , RTrim()
String.prototype.ALLTrim = function(){
// 去除所有空格
return this.replace(/\s+/g,"");
}
String.prototype.LRTrim = function(){
// 去除两头空格
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function(){
// 去除左空格
return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function(){
// 去除右空格
return this.replace(/(\s*$)/g, "");
}
//-->
</SCRIPT>
<body>
<input type="text" value=" 到 处 都 是 空 格 " id="space" size="30">
<input type="button" id="btnId1" value="去全部空格" οnclick="javascript:document.getElementById('space').value=document.getElementById('space').value.ALLTrim();document.getElementById('space').select();">
<input type="button" id="btnId2" value="去前后空格" οnclick="javascript:document.getElementById('space').value=document.getElementById('space').value.LRTrim();document.getElementById('space').select();">
<input type="button" id="btnId3" value="去前空格" οnclick="javascript:document.getElementById('space').value=document.getElementById('space').value.LTrim();document.getElementById('space').select();">
<input type="button" id="btnId4" value="去后空格" οnclick="javascript:document.getElementById('space').value=document.getElementById('space').value.RTrim();document.getElementById('space').select();">
<input type="button" id="btnId5" value=" 还 原 " οnclick="javascript:document.getElementById('space').value=' 到 处 都 是 空 格 ';">
</body>
</html>
js 去空格
最新推荐文章于 2020-07-01 09:47:31 发布