最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS字符串函數(shù)擴(kuò)展代碼

 更新時(shí)間:2011年09月13日 22:29:32   作者:  
JS字符串函數(shù)擴(kuò)展代碼,大家可以參考下prototype的使用方法,擴(kuò)展自己的字符串處理函數(shù)。
復(fù)制代碼 代碼如下:

/****************************************************
*CreateBy:joe zhou
*CreateDate:2011-9-4
*Description:字符串輔助函數(shù)
****************************************************/
//String.prototype = {
// caption: function () {
// },
// leftPad: function (padChar, width) {
// if (this.length >= width) {
// return this;
// }
// }
//};
String.prototype.padLeft = function (padChar, width) {
var ret = this;
while (ret.length < width) {
if (ret.length + padChar.length < width) {
ret = padChar + ret;
}
else {
ret = padChar.substring(0, width-ret.length) + ret;
}
}
return ret;
};
String.prototype.padRight = function (padChar, width) {
var ret = this;
while (ret.length < width) {
if (ret.length + padChar.length < width) {
ret += padChar;
}
else {
ret += padChar.substring(0, width - ret.length);
}
}
return ret;
};
String.prototype.trim = function () {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
};
String.prototype.trimLeft = function () {
return this.replace(/^\s+/, '');
};
String.prototype.trimRight = function () {
return this.replace(/\s+$/, '');
};
String.prototype.caption = function () {
if (this) {
return this.charAt(0).toUpperCase() + this.substr(1);
}
return this;
};
String.prototype.reverse = function () {
var ret = '';
for (var i = this.length - 1; i >= 0; i--) {
ret += this.charAt(i);
}
return ret;
};
String.prototype.startWith = function (compareValue, ignoreCase) {
if (ignoreCase) {
return this.toLowerCase().indexOf(compareValue.toLowerCase()) == 0;
}
return this.indexOf(compareValue) == 0
};
String.prototype.endWith = function (compareValue, ignoreCase) {
if (ignoreCase) {
return this.toLowerCase().lastIndexOf(compareValue.toLowerCase()) == this.length - compareValue.length;
}
return this.lastIndexOf(compareValue) == this.length - compareValue.length;
};

相關(guān)文章

最新評(píng)論

马关县| 蒙阴县| 花莲县| 黄陵县| 瑞安市| 准格尔旗| 铁岭县| 东光县| 龙陵县| 龙陵县| 富阳市| 兴安盟| 双流县| 沙雅县| 浙江省| 当阳市| 于田县| 卢湾区| 湖口县| 怀集县| 家居| 大安市| 东台市| 九寨沟县| 苏尼特左旗| 普安县| 丘北县| 千阳县| 贵州省| 汤原县| 遵化市| 山东| 玛纳斯县| 凤台县| 进贤县| 临猗县| 玛多县| 凤城市| 乌兰浩特市| 乌恰县| 同心县|