常用JS汇总
01、 取文档url参数值
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
02、日期格式化为字符串
if (typeof Date.prototype.format !== 'function') { //先检查一下是否已经定义了这个原型扩展方法,避免覆盖。
//时间格式化
Date.prototype.format = function (format) {
/*
* eg:format="yyyy-MM-dd hh:mm:ss";
*/
if (!format) {
format = "yyyy-MM-dd hh:mm:ss";
}
var o = {
"M+": this.getMonth() + 1, // month
"d+": this.getDate(), // day
"h+": this.getHours(), // hour
"m+": this.getMinutes(), // minute
"s+": this.getSeconds(), // second
"q+": Math.floor((this.getMonth() + 3) / 3), // quarter
"S": this.getMilliseconds()
// millisecond
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
};
03、EasyUI中grid日期格式化
function dateFormat(value,formatStr) {
var reg = new RegExp('/', 'g');
if (value == undefined) return "";
// 用1970 年 1 月 1 日 8 点 至今的毫秒数,转为时间值,如new Date(1391141532000)
var d = eval('new ' + value.replace(reg, ''));
var date = new Date(d);
if (date < new Date("1970-01-01")) {
return "";
}
return new Date(d).format(formatStr);
}
datagrid({ ......
{
field: 'ModifiedDate', title: "修改时间", width: '188px',
formatter: function (value, rec) {
return dateFormat(value, "yyyy-MM-dd hh:mm:ss");
}
},......
})
04、日期格式转换
function getDate(value) {
var reg = new RegExp('/', 'g');
var d = eval('new ' + value.replace(reg, ''));
return new Date(d).format('yyyy-MM-dd');
}
05、解决IE8以下版本不能设置文本框提示语的问题
//解决IE8以下版本不能设置文本框提示语的问题(代码待优化中.........)
(function () {
var body;
$(window).ready(function () {
body=$('body');
if (parseInt($.browser.version) <= 9) {
body.find('input[placeholder][type=text]').each(function () {
if($(this).val()==""){
if($(this).attr("placeholder")!=undefined){
$(this).val($(this).attr("placeholder"));
}
}
})
body.find('input[placeholder][type=text]').focus(function () {
if ($(this).attr("placeholder") == $(this).val()) {
$(this).val("");
}
}).blur(function () {
if ($(this).val().replace(/\s+/g, "") == "") {
$(this).val($(this).attr("placeholder"));
}
})
}
})
})(jQuery);
var Clear={
//清除提示语
clearplaceholder:function(thiss){
if(thiss.attr("placeholder")!=undefined && thiss.attr("placeholder")!=null){
return thiss.val().replace(thiss.attr("placeholder"),"").replace(/\s+/g,"");
}else{
return thiss.val().replace(/\s+/g,"");
}
}
}
常用JS汇总的更多相关文章
- 非常实用的PHP常用函数汇总
这篇文章主要介绍了非常实用的PHP常用函数,汇总了加密解密.字符串操作.文件操作.SQL注入等函数的实例与用法说明,在PHP项目开发中非常具有实用价值,需要的朋友可以参考下 本文实例总结了一些在php ...
- AngularJS进阶(十二)AngularJS常用知识汇总(不断更新中....)
AngularJS常用知识汇总(不断更新中....) 注:请点击此处进行充电! app.controller('editCtrl',['$http','$location','$rootScope', ...
- npm常用模块汇总
npm常用模块汇总: 点击插件名字,查看使用文档 npm常用模块汇总 node常用模块汇总 gulp常用插件汇总 npx 使用教程:npx使用教程 bable:bable这是JavaScript编译器 ...
- node常用模块汇总
node常用模块汇总: 点击插件名字,查看使用文档 npm常用模块汇总 node常用模块汇总 gulp常用插件汇总 mkdirp:在node.js中像mkdir -p一样递归创建目录及其子目录
- VSCode常用插件汇总
vscode常用插件汇总: 点击插件名字,查看使用文档 vscode-fileheader : 添加注释到文件头,并支持自动更新文件修改时间. EditorConfig for vs code : ...
- javascript常用知识汇总
javascript这个语言庞大而复杂,我用了三年多了,还是皮毛都不会.从刚开始的jquery,到后来的es6,每天都在学习,每天都在忘记. 1.禁止手机虚拟键盘弹出 在开发适配手机的页面时,出现了这 ...
- 20145222《信息安全系统设计基础》Linux常用命令汇总
学习Linux时常用命令汇总 通过Ctrl+f键可在该网页搜索到你想要的命令. Linux中命令格式为:command [options] [arguments] //中括号代表是可选的,即有些命令不 ...
- 常用js方法
function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...
- Oozie命令行常用命令汇总[转]
Oozie命令行常用命令汇总 有时候脚本跑多了就不愿意在OozieWeb端去看脚本的运行情况了.还好Oozie提供了很多命令行命令.能通过命令行直接检索自己想看到的脚本信息.在这里简单进行一下总结.一 ...
随机推荐
- android之 listview加载性能优化ViewHolder
在android开发中Listview是一个很重要的组件,它以列表的形式根据数据的长自适应展示具体内容,用户可以自由的定义listview每一列的布局,但当listview有大量的数据需要加载的时候, ...
- Python学习笔记——文件操作
python中,一切皆对象. 一.文件操作流程 (1)打开文件,得到一个文件句柄(对象),赋给一个对象: (2)通过文件句柄对文件进行操作: (3)关闭文件. 文件对象f通过open()函数来创建 ...
- How to relocate tablespace directory
I’ll demonstrate how to relocate a tablespace directory without the reconstruction of databases. I h ...
- 如何清除某条SQL的执行计划
如果遇到绑定窥探导致执行计划慢的情况,想要清除某条SQL的执行计划,让它硬解析,找了很久都没有找到直接操作share pool的方法(除非alter system flush shared_pool) ...
- pt-online-schema-change 实例
pt-pmp (http://www.cnblogs.com/ivictor/p/6012183.html) pt-online-schema-change (http://blog.csdn.net ...
- [linux] Nginx编译安装错误error: the HTTP rewrite module requires the PCRE library
nginx编译错误: 执行如下命令安装缺少的文件即可
- Abstract和Virtual和interface , 派生类中重写 override / new关键字
http://www.cnblogs.com/blsong/archive/2010/08/12/1798064.html C#中Abstract和Virtual 在C#的学习中,容易混淆virtua ...
- Web前端图表绘制JQuery插件jqplot
在此之前使用了Chart.js.Highcharts,首先了解一下这两款插件的优势与不足,然后再来了解jqplot. 1.Chart Chart中文官网:http://chartjs.cn/ 1.1优 ...
- windows server 2008服务器 做raid0
dell服务器,启动后,根据提示按F10进入raid设置,设置成raid0 我们的服务器是4块硬盘,每块600G,做raid0时,生成一个虚拟磁盘vdisk. 做完raid之后,做OS部署 重启服务器 ...
- (C#) 基本概念一览表
A abstract class An abstract class is a class that must be inherited and have the methods overridden ...