有什么方法可以去掉字符串左右两边的空格????? str=str.replace(/(^\s*)|(\s*$)/g, ""); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function trim(value){ var res = String(value).replace(/^[\s]+|[\s]+$/g,''); return res;} 自己来定义Trim LRrim RTrim<script language=javascript>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, "");}var s = " leading and trailing spaces ";window.alert(s + " (" + s.length + ")");s = s.Trim();window.alert(s + " (" + s.length + ")");</script> http://www.csdn.net/expert/topic/806/806410.xml?temp=.3242456 自己写一个function LTrim(tempString){ while (tempString.charAt(0) == ' ') { tempString= tempString.substring(1,tempString.length); } return tempString;}function RTrim(tempString){ while (tempString.charAt(tempString.length - 1) == ' ') { tempString= tempString.substring(0,tempString.length - 1); } return tempString;} ExtJs grid追加数据问题 js实现单元格改变背景色 帮我看看这段代码有什么问题?为什么提示An error occurred at line: 11 in the jsp file: /zixue-2.jsp 变于js变量范围 用javascript将iframe中的文本中的\r或\n替换为<br> 如何用jQuery处理播放器控件ID?谢谢! JS画流程节点问题 在线等一js 怎么判断dhtml中某个标签的属性为只读 关于获得鼠标在浏览器的位置的问题,谢谢! 超级难题,大家快来帮忙啊! 语言问题:可以这样用么
var res = String(value).replace(/^[\s]+|[\s]+$/g,'');
return res;
}
<script language=javascript>
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, "");}
var s = " leading and trailing spaces ";
window.alert(s + " (" + s.length + ")");
s = s.Trim();
window.alert(s + " (" + s.length + ")");
</script>
function LTrim(tempString){
while (tempString.charAt(0) == ' ') {
tempString= tempString.substring(1,tempString.length);
}
return tempString;
}
function RTrim(tempString){
while (tempString.charAt(tempString.length - 1) == ' ') {
tempString= tempString.substring(0,tempString.length - 1);
}
return tempString;
}