数码资讯
js中的字符串修剪()示例
例1: 测试JS扩展方法 合并一个空白的多个空白 (string.prototype.resetblank =功能){ / /字符串扩展 VaR的正则表达式= / / g +; 返回this.replace(正则表达式); }; 在window.onload =功能() { 你认为他行吗 警报(ST
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
例1:
测试JS扩展方法
合并一个空白的多个空白
(string.prototype.resetblank =功能){ / /字符串扩展
VaR的正则表达式= / / g +;
返回this.replace(正则表达式);
};
在window.onload =功能()
{
你认为他行吗
警报(STR);
STR =(str.resetblank / /);这样你就可以打电话,像C #!
警报(STR);
}
例二:
在盒子的两边清除
string.prototype.trim =函数(){
返回(this.replace /(^ *)|( * $ / g),);
};
合并一个空白的多个空白
string.prototype.resetblank =函数(){
VaR的正则表达式= / / g +;
返回this.replace(正则表达式);
};
预订号码
string.prototype.getnum =函数(){
VaR的正则表达式= / { ^ D} /克;
返回this.replace(正则表达式);
};
保持汉语
string.prototype.getcn =函数(){
VaR的正则表达式= / { ^ u4e00 - u9fa5 uf900 - ufa2d } /克;
返回this.replace(正则表达式);
};
将字符串转换为数字
string.prototype.toint =函数(){
返回isnan(parseInt(这))this.tostring():parseInt(本);
};
获取字节长度
string.prototype.getlen =函数(){
VaR的正则表达式= / ^ { u4e00 - u9fa5 uf900 - ufa2d } + $ /;
如果(regex.test(这)){
返回this.length * 2;
{人}
无功omatches = this.match( / { 设备- xff } / G);
无功olength = this.length * 2 omatches.length;
返回olength;
}
};
获取文件名
string.prototype.getfilename =函数(){
VaR的正则表达式= / / ^。*({ ^ / } *。* $ /);
返回this.replace(正则表达式,1美元);
};
获取文件扩展名
string.prototype.getextensionname =函数(){
VaR的正则表达式= / ^。* / / } { ^ *(。{ ^ } *。* $ /);
返回this.replace(正则表达式,1美元);
};
替换所有
string.prototype.replaceall =功能(真的,用的,忽略大小写){
如果(!RegExp.prototype.isPrototypeOf(确实)){
返回this.replace(new RegExp(确实,((忽略大小写GI:G)),用);
{人}
返回this.replace(确实,用);
}
};
加上刘静宁2010-12-09 /格式字符串
字符串=函数(){
如果(arguments.length = = 0){
返回' ';
}
如果(arguments.length = = 1){
返回参数{ 0 };
}
var();
var args =参数;
var参数=参数{ 0 }。替换(寄存器,函数($ 0,$ 1){)
Return args{parseInt ($1) + 1};
});
返回结果;
};
数字零
number.prototype.lenwithzero =功能(ocount){
无功strtext = this.tostring();
而(strtext.length < ocount){
strtext = 0+ strtext;
}
返回strtext;
};
减少Unicode
number.prototype.chrw =函数(){
返回String.fromCharCode(本);
};
/从小到大数组的数字顺序
array.prototype.min2max =函数(){
无功ovalue;
对于(var i = 0;i < this.length;i++){
对于(var j=0;j < i;j + +){
如果(此{ } <此{ } }){
ovalue =这{我};
这个{ } =这个{ };
这{ } = ovalue {J}.;
}
}
}
返回此;
};
以降序排列的数字数组
array.prototype.max2min =函数(){
无功ovalue;
对于(var i = 0;i < this.length;i++){
对于(var j=0;j < i;j + +){
如果(此{ }此{ } }){
ovalue =这{我};
这个{ } =这个{ };
这{ } = ovalue {J}.;
}
}
}
返回此;
};
获取数组的最大数目
array.prototype.getmax =函数(){
无功ovalue = 0;
对于(var i = 0;i < this.length;i++){
如果(这{我} > ovalue){
ovalue =这{我};
}
}
返回ovalue;
};
数组增益的数量很少。
array.prototype.getmin =函数(){
无功ovalue = 0;
对于(var i = 0;i < this.length;i++){
如果(这{我} < ovalue){
ovalue =这{我};
}
}
返回ovalue;
};
中文表格/当前时间
date.prototype.getcndate =函数(){
无功odatetext =;
odatetext = this.getfullyear(LenWithZero)+新(4)(24180)(chrw数。);
odatetext = this.getmonth(LenWithZero)+新(2)(26376)(chrw数。);
odatetext = this.getdate(LenWithZero)+新(2)(26085)(chrw数。);
odatetext = this.gethours(LenWithZero)+新(2)(26102)(chrw数。);
odatetext = this.getminutes(LenWithZero)+新(2)(20998)(chrw数。);
odatetext = this.getseconds(LenWithZero)+新(2)(31186)(chrw数。);
odatetext =新的号码(32),ChrW(新)+数字(32),ChrW(新)+数字(26143),ChrW(新)+数字(26399),ChrW(新)+字符串('26085199682010819977222352011620845)。Substr(这。getday)*(5, 5)(Toint(。)chrw);
返回odatetext;
};
扩展日期格式
date.prototype.format =函数(格式){
var { { { {
M +:this.getmonth(+ 1) / /月
D:(这个getdate), / /天
H:(这个,获得当前的小时)% 12 = = 012:(这个,获得当前的小时)% 12, / /小时
H:(这个,获得当前的小时) / /小时。
M + :(这个,获得当前的分钟), / /分
+:(这个,获得当前的秒), / /
Q+:Math.floor((,获得当前的月份)(+ 3)/ 3), / /季度
S:(这个。getmilliseconds) / /小姐
};
var周= {
0 u65e5
1 u4e00
2 u4e8c
3 u4e09
4 u56db
5 u4e94
6 u516d
};
如果((y +)测试(格式)){
格式= format.replace(regexp。1美元,((this.getfullyear()+)。Substr(4—9。1美元。长度));
}
如果((e +)测试(格式)){
格式= format.replace(regexp。1美元,((regexp美元。1.length > 1)(regexp。1.length > 2美元 u661f u671f u5468 ):)+周{ this.getday()+}));
}
对于(var在o中){
如果(新规则((钾))。试验(格式)){
格式= format.replace(regexp。1美元(1美元= = 1.length regexp。)(O { }(K):(00 + O K({ })。Substr(长+ O { k }))));
}
}
返回格式;
}
date.prototype.diff =功能(间隔,objdate){
如果参数是不足或不 / / objdate返回未定义的数据类型
如果(arguments.length<2 | | objdate.constructor!=日期){未定义的返回;}
开关(间隔){
计算 /秒
例:返回parseInt((objdate这) / 1000);
计算差异
case'n:返回parseInt((objdate这) / 60000);
时间差
case'h:返回parseInt((objdate这) / 3600000);
计算日差
案例:parseInt(会返回(objdate这) / 86400000);
周差计算
case'w:返回parseInt((objdate -)/(86400000×7));
计算差异
案例是:返回(objdate.getmonth)+(1)+((objdate.getfullyear()- this.getfullyear())* 12)-(this.getmonth()+ 1);
差异计算
case'y:返回objdate.getfullyear()-()this.getfullyear;
输入错误
默认值:返回未定义;
}
};
检测是空的
object.prototype.isnullorempty =函数(){
var obj =这;
var标志= false;
如果(obj = = null obj =定义的| | | | typeof(obj)= 'undefined'obj = ={ | |)
标志=真;
否则如果}(typeof(obj)= = 'String'){
obj = obj.trim();
如果(obj = =){ / /是空的
标志=真;
否则,{ }不为空
obj = obj.touppercase();
如果(obj = = 'null'obj = = 'undefined的obj = = | | | | {{ })
标志=真;
}
}
}
{其他
标志=假;
}
返回标志;
以上是本文的全部内容,希望大家能喜欢。
测试JS扩展方法
合并一个空白的多个空白
(string.prototype.resetblank =功能){ / /字符串扩展
VaR的正则表达式= / / g +;
返回this.replace(正则表达式);
};
在window.onload =功能()
{
你认为他行吗
警报(STR);
STR =(str.resetblank / /);这样你就可以打电话,像C #!
警报(STR);
}
例二:
在盒子的两边清除
string.prototype.trim =函数(){
返回(this.replace /(^ *)|( * $ / g),);
};
合并一个空白的多个空白
string.prototype.resetblank =函数(){
VaR的正则表达式= / / g +;
返回this.replace(正则表达式);
};
预订号码
string.prototype.getnum =函数(){
VaR的正则表达式= / { ^ D} /克;
返回this.replace(正则表达式);
};
保持汉语
string.prototype.getcn =函数(){
VaR的正则表达式= / { ^ u4e00 - u9fa5 uf900 - ufa2d } /克;
返回this.replace(正则表达式);
};
将字符串转换为数字
string.prototype.toint =函数(){
返回isnan(parseInt(这))this.tostring():parseInt(本);
};
获取字节长度
string.prototype.getlen =函数(){
VaR的正则表达式= / ^ { u4e00 - u9fa5 uf900 - ufa2d } + $ /;
如果(regex.test(这)){
返回this.length * 2;
{人}
无功omatches = this.match( / { 设备- xff } / G);
无功olength = this.length * 2 omatches.length;
返回olength;
}
};
获取文件名
string.prototype.getfilename =函数(){
VaR的正则表达式= / / ^。*({ ^ / } *。* $ /);
返回this.replace(正则表达式,1美元);
};
获取文件扩展名
string.prototype.getextensionname =函数(){
VaR的正则表达式= / ^。* / / } { ^ *(。{ ^ } *。* $ /);
返回this.replace(正则表达式,1美元);
};
替换所有
string.prototype.replaceall =功能(真的,用的,忽略大小写){
如果(!RegExp.prototype.isPrototypeOf(确实)){
返回this.replace(new RegExp(确实,((忽略大小写GI:G)),用);
{人}
返回this.replace(确实,用);
}
};
加上刘静宁2010-12-09 /格式字符串
字符串=函数(){
如果(arguments.length = = 0){
返回' ';
}
如果(arguments.length = = 1){
返回参数{ 0 };
}
var();
var args =参数;
var参数=参数{ 0 }。替换(寄存器,函数($ 0,$ 1){)
Return args{parseInt ($1) + 1};
});
返回结果;
};
数字零
number.prototype.lenwithzero =功能(ocount){
无功strtext = this.tostring();
而(strtext.length < ocount){
strtext = 0+ strtext;
}
返回strtext;
};
减少Unicode
number.prototype.chrw =函数(){
返回String.fromCharCode(本);
};
/从小到大数组的数字顺序
array.prototype.min2max =函数(){
无功ovalue;
对于(var i = 0;i < this.length;i++){
对于(var j=0;j < i;j + +){
如果(此{ } <此{ } }){
ovalue =这{我};
这个{ } =这个{ };
这{ } = ovalue {J}.;
}
}
}
返回此;
};
以降序排列的数字数组
array.prototype.max2min =函数(){
无功ovalue;
对于(var i = 0;i < this.length;i++){
对于(var j=0;j < i;j + +){
如果(此{ }此{ } }){
ovalue =这{我};
这个{ } =这个{ };
这{ } = ovalue {J}.;
}
}
}
返回此;
};
获取数组的最大数目
array.prototype.getmax =函数(){
无功ovalue = 0;
对于(var i = 0;i < this.length;i++){
如果(这{我} > ovalue){
ovalue =这{我};
}
}
返回ovalue;
};
数组增益的数量很少。
array.prototype.getmin =函数(){
无功ovalue = 0;
对于(var i = 0;i < this.length;i++){
如果(这{我} < ovalue){
ovalue =这{我};
}
}
返回ovalue;
};
中文表格/当前时间
date.prototype.getcndate =函数(){
无功odatetext =;
odatetext = this.getfullyear(LenWithZero)+新(4)(24180)(chrw数。);
odatetext = this.getmonth(LenWithZero)+新(2)(26376)(chrw数。);
odatetext = this.getdate(LenWithZero)+新(2)(26085)(chrw数。);
odatetext = this.gethours(LenWithZero)+新(2)(26102)(chrw数。);
odatetext = this.getminutes(LenWithZero)+新(2)(20998)(chrw数。);
odatetext = this.getseconds(LenWithZero)+新(2)(31186)(chrw数。);
odatetext =新的号码(32),ChrW(新)+数字(32),ChrW(新)+数字(26143),ChrW(新)+数字(26399),ChrW(新)+字符串('26085199682010819977222352011620845)。Substr(这。getday)*(5, 5)(Toint(。)chrw);
返回odatetext;
};
扩展日期格式
date.prototype.format =函数(格式){
var { { { {
M +:this.getmonth(+ 1) / /月
D:(这个getdate), / /天
H:(这个,获得当前的小时)% 12 = = 012:(这个,获得当前的小时)% 12, / /小时
H:(这个,获得当前的小时) / /小时。
M + :(这个,获得当前的分钟), / /分
+:(这个,获得当前的秒), / /
Q+:Math.floor((,获得当前的月份)(+ 3)/ 3), / /季度
S:(这个。getmilliseconds) / /小姐
};
var周= {
0 u65e5
1 u4e00
2 u4e8c
3 u4e09
4 u56db
5 u4e94
6 u516d
};
如果((y +)测试(格式)){
格式= format.replace(regexp。1美元,((this.getfullyear()+)。Substr(4—9。1美元。长度));
}
如果((e +)测试(格式)){
格式= format.replace(regexp。1美元,((regexp美元。1.length > 1)(regexp。1.length > 2美元 u661f u671f u5468 ):)+周{ this.getday()+}));
}
对于(var在o中){
如果(新规则((钾))。试验(格式)){
格式= format.replace(regexp。1美元(1美元= = 1.length regexp。)(O { }(K):(00 + O K({ })。Substr(长+ O { k }))));
}
}
返回格式;
}
date.prototype.diff =功能(间隔,objdate){
如果参数是不足或不 / / objdate返回未定义的数据类型
如果(arguments.length<2 | | objdate.constructor!=日期){未定义的返回;}
开关(间隔){
计算 /秒
例:返回parseInt((objdate这) / 1000);
计算差异
case'n:返回parseInt((objdate这) / 60000);
时间差
case'h:返回parseInt((objdate这) / 3600000);
计算日差
案例:parseInt(会返回(objdate这) / 86400000);
周差计算
case'w:返回parseInt((objdate -)/(86400000×7));
计算差异
案例是:返回(objdate.getmonth)+(1)+((objdate.getfullyear()- this.getfullyear())* 12)-(this.getmonth()+ 1);
差异计算
case'y:返回objdate.getfullyear()-()this.getfullyear;
输入错误
默认值:返回未定义;
}
};
检测是空的
object.prototype.isnullorempty =函数(){
var obj =这;
var标志= false;
如果(obj = = null obj =定义的| | | | typeof(obj)= 'undefined'obj = ={ | |)
标志=真;
否则如果}(typeof(obj)= = 'String'){
obj = obj.trim();
如果(obj = =){ / /是空的
标志=真;
否则,{ }不为空
obj = obj.touppercase();
如果(obj = = 'null'obj = = 'undefined的obj = = | | | | {{ })
标志=真;
}
}
}
{其他
标志=假;
}
返回标志;
以上是本文的全部内容,希望大家能喜欢。
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。