给你的Javascript中的String加上Trim的功能!

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 例子
var s = "    leading and trailing spaces    ";

window.alert(s + " (" + s.length + ")");

s = s.trim();
window.alert(s + " (" + s.length + ")");

posted @ 2006-08-21 02:52  Pootow  阅读(861)  评论(0编辑  收藏  举报