亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

在Javascript中為String對(duì)象添加trim,ltrim,rtrim方法

 更新時(shí)間:2006年09月22日 00:00:00   作者:  
利用Javascript中每個(gè)對(duì)象(Object)的prototype屬性我們可以為Javascript中的內(nèi)置對(duì)象添加我們自己的方法和屬性。
以下我們就用這個(gè)屬性來為String對(duì)象添加三個(gè)方法:Trim,LTrim,RTrim(作用和VbScript中的同名函數(shù)一樣)
復(fù)制代碼 代碼如下:
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, "");
}

怎么樣,簡單吧,下面看一個(gè)使用的實(shí)例:
復(fù)制代碼 代碼如下:

<script language=javascript>
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 + ")");
</script>

相關(guān)文章

最新評(píng)論