在javascript中如何去除字符串两头的空格
2006-12-11 14:09
441 查看
<SCRIPT LANGUAGE="JavaScript">
<!--
// Trim() , Ltrim() , RTrim()
String.prototype.Trim = 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>
使用例子如下:
<input type="text" value=" 前后都是空格 " id="space">
<input type="button" value="去前后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.Trim();document.getElementById('space').select();">
<input type="button" value="去前空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.LTrim();document.getElementById('space').select();">
<input type="button" value="去后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.RTrim();document.getElementById('space').select();">
<input type="button" value="还原" onclick="javascript:document.getElementById('space').value=' 前后都是空格 ';">
相关文章推荐
- JavaScript中如何去除字符串前后的空格?
- js---在前端开发中,如何通过正则表达式去除字符串string首尾的空格,JavaScript正则去除首尾空格
- JavaScript去除字符串首尾空格
- JavaScript去除字符串两边空格trim
- javascript去除字符串空格的函数
- JavaScript 去除字符串中的空格
- 一个用JavaScript去除字符串两端空格的function
- javascript:去除字符串的前后空格
- javascript去除字符串左右两端的空格
- JavaScript去除字符串两边空格 == trim
- javascript去除字符串左右两端的空格
- javascript:去除字符串的前后空格
- javascript 去除字符串中所有的空格or前后的双引号
- oracle中如何对字符串进行去除空格的方法
- 用JavaScript去除字符串的首尾空格。
- javascript:去除字符串的前后空格
- JavaScript去除字符串两边空格trim
- javascript去除字符串中的空格
- javascript去除字符串空格
- javascript去除字符串空格的函数