String.prototype.trim = function()
{
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}// 有空格的字符串
var s = " leading and trailing spaces ";// 显示 " leading and trailing spaces (35)"
window.alert(s + " (" + s.length + ")");// 删除前后空格
s = s.trim();
{
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}// 有空格的字符串
var s = " leading and trailing spaces ";// 显示 " leading and trailing spaces (35)"
window.alert(s + " (" + s.length + ")");// 删除前后空格
s = s.trim();
解决方案 »
- 求网站常用JS特效展示或代码!!!
- 如何通过接盘自动选择li的下一个兄弟li
- 请问一个有关FireFox起始页面的问题
- 诚寻Yahoo Widget 开发者,项目开发合作
- 搞不懂这段 JavaScript 代码,出自 FCKeditor
- JAVASCRIPT打开同一个WORD时,前一个自动关闭
- 哪个函数可以返回当前日期时间的数字格式?
- javascript截取前面N个字代码怎样写?
- 请问parent.window.location.href=""的使用?
- 如何给这个进度条程序加一入口,让它真实地反应sample.htm页面的载入进度
- MicroSoft JScript 和JAVAScript之间有什么异同?答的越详细给分越多!
- 请问如何对ListBox中的内容进行排序?
return this.replace(/(^\s*)|(\s*$)/g, "");