一、获取地址栏参数

 /*根据name获取URL参数*/
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr().match(reg);
if (r != null) return unescape(r[]); return null;
}

二、提取文本中中文

 <script type="text/javascript">
var str="怎样从一个Html页面中提取所有汉字呢?不能有其它Html代码。";
str=str.replace(/[^\u4e00-\u9fa5]/gi,"");
</script>

三、数组去重

 //数组去重
Array.prototype.uniqueNo = function()
{
this.sort();
var re=[this[]];
for(var i = ; i < this.length; i++)
{
if( this[i] !== re[re.length-])
{
re.push(this[i]);
}
}
return re;
}

四、整数正则验证

 onkeyup="this.value=this.value.replace(/\D/g,'')"

五、小数正则验证

 var pattern = /^\d+(\.\d+)?$/;

六、绑定回车事件

 document.onkeydown = function (event) {
e = event ? event : (window.event ? window.event : null);
if (e.keyCode == ) {
$('#submit').click();
}
}

七、获取当前时间(yyyy-dd-mm hh:mm:ss)

 function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + ;
var strDate = date.getDate();
if (month >= && month <= ) {
month = "" + month;
}
if (strDate >= && strDate <= ) {
strDate = "" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}

八、生成32位GUID

 function GUID() {
this.date = new Date(); /* 判断是否初始化过,如果初始化过以下代码,则以下代码将不再执行,实际中只执行一次 */
if (typeof this.newGUID != 'function') { /* 生成GUID码 */
GUID.prototype.newGUID = function () {
this.date = new Date(); var guidStr = '';
sexadecimalDate = this.hexadecimal(this.getGUIDDate(), );
sexadecimalTime = this.hexadecimal(this.getGUIDTime(), );
for (var i = ; i < ; i++) {
guidStr += Math.floor(Math.random() * ).toString();
}
guidStr += sexadecimalDate;
guidStr += sexadecimalTime;
while (guidStr.length < ) {
guidStr += Math.floor(Math.random() * ).toString();
}
return this.formatGUID(guidStr);
}
/* * 功能:获取当前日期的GUID格式,即8位数的日期:19700101 * 返回值:返回GUID日期格式的字条串 */
GUID.prototype.getGUIDDate = function () {
return this.date.getFullYear() + this.addZero(this.date.getMonth() + ) + this.addZero(this.date.getDay());
}
/* * 功能:获取当前时间的GUID格式,即8位数的时间,包括毫秒,毫秒为2位数:12300933 * 返回值:返回GUID日期格式的字条串 */
GUID.prototype.getGUIDTime = function () {
return this.addZero(this.date.getHours()) + this.addZero(this.date.getMinutes()) + this.addZero(this.date.getSeconds()) + this.addZero(parseInt(this.date.getMilliseconds() / ));
}
/* * 功能: 为一位数的正整数前面添加0,如果是可以转成非NaN数字的字符串也可以实现 * 参数: 参数表示准备再前面添加0的数字或可以转换成数字的字符串 * 返回值: 如果符合条件,返回添加0后的字条串类型,否则返回自身的字符串 */
GUID.prototype.addZero = function (num) {
if (Number(num).toString() != 'NaN' && num >= && num < ) {
return '' + Math.floor(num);
} else {
return num.toString();
}
}
/* * 功能:将y进制的数值,转换为x进制的数值 * 参数:第1个参数表示欲转换的数值;第2个参数表示欲转换的进制;第3个参数可选,表示当前的进制数,如不写则为10 * 返回值:返回转换后的字符串 */GUID.prototype.hexadecimal = function (num, x, y) {
if (y != undefined) { return parseInt(num.toString(), y).toString(x); }
else { return parseInt(num.toString()).toString(x); }
}
/* * 功能:格式化32位的字符串为GUID模式的字符串 * 参数:第1个参数表示32位的字符串 * 返回值:标准GUID格式的字符串 */
GUID.prototype.formatGUID = function (guidStr) {
var str1 = guidStr.slice(, ), str2 = guidStr.slice(, ), str3 = guidStr.slice(, ), str4 = guidStr.slice(, ), str5 = guidStr.slice();
return str1 + str2 + str3 + str4 + str5;
}
}
}

九、UTF8编码

 //UTF字符转换
var UTFTranslate = {
Change:function(pValue){
return pValue.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
},
ReChange:function(pValue){
return unescape(pValue.replace(/&#x/g,'%u').replace(/\\u/g,'%u').replace(/;/g,''));
}
};

十、json日期格式化

//yyyy-MM-dd HH:mm:SS
function getDateTime(date) {
var year = date.getFullYear();
var month = date.getMonth() + ;
var day = date.getDate();
var hh = date.getHours();
var mm = date.getMinutes();
var ss = date.getSeconds();
if (day < )
day = '' + day;
if (month < )
month = '' + month;
if (hh < )
hh = '' + hh;
if (mm < )
mm = '' + mm;
if (ss < )
ss = '' + ss;
return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss;
}
function ConvertJSONDateToJSDate(jsondate) {
var date = new Date(parseInt(jsondate.replace("/Date(", "").replace(")/", ""), ));
return date;
}

  

常用js归纳的更多相关文章

  1. 基础常用JS函数和语法

    100多个基础常用JS函数和语法集合大全  来源:http://www.cnblogs.com/hnyei/p/4605103.html 网站特效离不开脚本,javascript是最常用的脚本语言,我 ...

  2. 常用js方法

    function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...

  3. 常用JS正则表达式

    常用JS正则表达式 收集一些常用的JavaScript正则表达式匹配规则,比如匹配电话号码.Email.中文字符.身份证号.邮编.QQ号.过滤空白行.匹配特定数字等.觉得这玩意是很有用的,只不过自己水 ...

  4. 常用js方法整理common.js

    项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...

  5. 原生JS研究:学习jquery源码,收集整理常用JS函数

    原生JS研究:学习jquery源码,收集整理常用JS函数: 1. JS获取原生class(getElementsByClass) 转自:http://blog.csdn.net/kongjiea/ar ...

  6. 项目中常用js方法整理common.js

    抽空把项目中常用js方法整理成了common.js,都是网上搜集而来的,大家一起分享吧. var h = {}; h.get = function (url, data, ok, error) { $ ...

  7. 常用js正则表达式大全

    常用js正则表达式大全.一.校验数字的js正则表达式 1 数字:^[0-9]*$ 2 n位的数字:^\d{n}$ 3 至少n位的数字:^\d{n,}$ 4 m-n位的数字:^\d{m,n}$ 5 零和 ...

  8. api日常总结:前端常用js函数和CSS常用技巧

    我的移动端media html{font-size:10px} @media screen and (min-width:321px) and (max-width:375px){html{font- ...

  9. web前端关于html转义符的常用js函数

    web前端关于html转义符的常用js函数 //去掉html标签 function removeHtmlTab(tab) { return tab.replace(/<[^<>]+? ...

随机推荐

  1. EasyUI datagrid 日期时间格式化

    EasyUI datagrid中显示日期时间时,会显示为以下不太直观的数值: 添加以下JavaScript脚本,然后在field中添加 formatter: DateTimeFormatter 即可. ...

  2. 无脑简单 命令升级git Centos

    yum remove git yum install zlib (系统默认已经装上) yum install zlib-devel ># wget https://github.com/git/ ...

  3. css3制作炫酷导航栏效果

    今天主要利用hover选择器.鼠标滑过查看效果. 一.普通导航栏 Home Content Service Team Contact 对于这种普通的导航栏,只是鼠标滑过的时候颜色会变,所以思路变得很简 ...

  4. 用Kotlin语言重新编写Plaid APP:经验教训(I)

    原文标题:Converting Plaid to Kotlin: Lessons learned (Part 1) 原文链接:http://antonioleiva.com/plaid-kotlin- ...

  5. SEED信息安全实验系列:缓冲区溢出漏洞实验

    缓冲区溢出漏洞实验 本课程详细出自http://www.shiyanlou.com/courses/231,转载请注明出处. 一.实验描述 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情 ...

  6. Highchart基础教程-图表配置

    一.图表容器: Highcharts 实例化中绑定容器的两种方式: 1.通过 dom 调用 highcharts() 函数的方式 $("#container").highchart ...

  7. IT软件的编程方向 - 进阶者系列 - 学习者系列文章

    IT软件经过了这么些年的发展,已经形成了很多的软件公司和开发团队,而且当前编程语言也有很多种,让开发人员能够有很大的选择.现在国际上的开发阵营基本分为ASP.NET.JAVA和PHP三种,但是每种开发 ...

  8. CentOS安装SVN服务器

    Step1:安装svn服务器 $ yum install subversion Step2:创建SVN版本库目录 $ mkdir /workplace/svnrepos Step3:创建版本库 $ s ...

  9. Eclipse中JAR System library 没有怎么添加?

    1.打开  >>  Eclipse 2.右击项目   >>  Build path  >>  Configure Build path  如图1: 图1 3.进入 ...

  10. sql语句查询经纬度范围(转载,源链接失效)

    MySQL性能调优 – 使用更为快速的算法进行距离 最近遇到了一个问题,通过不断的尝试最终将某句原本占据近1秒的查询优化到了0.01秒,效率提高了100倍. 问题是这样的,有一张存放用户居住地点经纬度 ...