javacsripte常用技巧总结

javacsripte常用技巧总结

ID:35294563

大小:221.00 KB

页数:35页

时间:2019-03-23

javacsripte常用技巧总结_第1页
javacsripte常用技巧总结_第2页
javacsripte常用技巧总结_第3页
javacsripte常用技巧总结_第4页
javacsripte常用技巧总结_第5页
资源描述:

《javacsripte常用技巧总结》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、JavaScript常用技巧1、原生JavaScript实现字符串长度截取1234567891011121314151617181920function cutstr(str,len){    var temp;    var icount=0;    var patrn=/[^x00-xff]/;    var strre= "";    for (var i=0;i

2、ubstr(i,1);            if (patrn.exec(temp)== null){                icount=icount+1            } else {                icount=icount+2            }            strre+=temp        } else {            break        }    }    return strre+ "..."}2、原生JavaScri

3、pt获取域名主机1function getHost(url){23456789101112    var host= "null";    if(typeof url== "undefined"

4、

5、 null ==url){        url=window.location.href;    }    var regex=/^w+://([^/]*).*/;    var match=url.match(regex);    if(typeof match!= "undefined" &

6、& null !=match){        host=match[1];    }    return host;}3、原生JavaScript清除空格1234String.prototype.trim= function(){    var reExtraSpace=/^s*(.*?)s+$/;    return this.replace(reExtraSpace, "$1")}4、原生JavaScript替换全部123String.prototype.replaceAll= functi

7、on(s1,s2){    return this.replace(new RegExp(s1, "gm"),s2)}5、原生JavaScript转义html标签123function HtmlEncode(text){    return text.replace(/&/g, '&').replace(/"/g,'"').replace(//g, '>')}6、原生JavaScript还原html标签123function HtmlDecode(text){

8、    return text.replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>')}7、原生JavaScript时间日期格式转换123456789101112131415161718Date.prototype.Format= function(formatStr){    var str=formatStr;    var Week=['日', '一', '二', '三', '四', '五', '六

9、'];    str=str.replace(/yyyy

10、YYYY/, this.getFullYear());    str=str.replace(/yy

11、YY/,(this.getYear()%100)>9?(this.getYear()%100).toString(): '0' +(this.getYear()%100));    str=str.replace(/MM/,(this.getMonth()+1)>9?(this.getMonth()+1).toString(): '0'+(th

12、is.getMonth()+1));    str=str.replace(/M/g,(this.getMonth()+1));    str=str.replace(/w

13、W/g,Week[this.getDay()]);    str=str.replace(/dd

14、DD/, this.getDate()>9? this.getDate().toString(): '0' +this.getDate());    str=str.replace(/d

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。