1://截取url带过来的参数

function getvl(name) {
var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
return reg.test(location.href) ? decodeURI(RegExp.$2.replace(/\+/g, " ")) : '';
}; 2://判断对象的长度
Object.size = function (obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
3:
// 转换字符串成时间 function changeTime(t, nohour) {
    if (String(t).indexOf("-") >= 0 || t == null) {
return t = '';
} else {
var date = new Date(t);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
return nohour ? Y + M + D : Y + M + D + h + m + s;
}
}
4://纯数字且不能输入空格且不能输入小数点
// isZero == zero可为零
// isZero == unNone不能为空格
function keepNum(obj, num, isZero) {
var $this = $(obj);
var v = $this.val();
if (isNaN(v) || (v.indexOf('.') != -1)) {
var values = v.slice(0, -1);
if (isNaN(values)) {
values = ''
}
values = values.replace(/\s/g, "");
$this.val(values);
} else { //去除空格
$this.val(v.replace(/\s/g, ""));
}
num && (function () {
var newValue = $this.val();
if (!isNaN(newValue) && newValue != '') {
if (isZero == 'zero') {
if (newValue < 0) {
newValue = 0;
} else if (newValue > num) {
newValue = num;
}
} else {
if (newValue < 1) {
newValue = 1;
} else if (newValue > num) {
newValue = num;
}
} } else {
if (isZero == 'unNone') {
if (newValue < 1) {
newValue = 1;
} else if (newValue > num) {
newValue = num;
}
}
}
$this.val(newValue);
})()
}
5://纯数字且不能输入空格且不能输入小数点可以是负数 默认没有小数
function keepSR(obj, num,maxlength) {
var imposeNum = maxlength ? (maxlength+1) : 1;
var $this = $(obj);
var v = $this.val();
if (isNaN(v)) {
if(v!='-'){
var values = v.slice(0, -1);
if (isNaN(values)) {
values = ''
}
values = values.replace(/\s/g, "");
$this.val(values);
}
} else if (v.indexOf('.') != -1) {
if (v.split('.')[1].length == imposeNum) {
var values = v.slice(0, -1);
$this.val(values);
} else if (v.split('.')[1].length > imposeNum) {
$this.val('');
}
}else { //去除空格
$this.val(v.replace(/\s/g, ""));
}
num && (function () {
var newValue = $this.val();
if (!isNaN(newValue) && newValue != '') {
if (newValue < -num) {
newValue = -num;
} else if (newValue > num) {
newValue = num;
}
}
$this.val(newValue);
})()
}
//数字且最限制小数点位数,(默认三位)且不能输入空格且可以为0
function keepSH(obj, num ,maxlength) {
var $this = $(obj);
var v = $this.val();
var imposeNum = maxlength ? (maxlength+1) : 4;//限制小数点数量,默认为小数点后3位
if (isNaN(v)) {
var values = v.slice(0, -1);
if (isNaN(values)) {
values = ''
}
$this.val(values);
} else if (v.indexOf('.') != -1) {
if (v.split('.')[1].length == imposeNum) {
var values = v.slice(0, -1);
$this.val(values);
} else if (v.split('.')[1].length > imposeNum) {
$this.val('');
}
} else {
$this.val(v.replace(/\s/g, ""));
} var newValue = $this.val();
if (!isNaN(newValue) && newValue != '') {
if (newValue > num) {
newValue = num;
}
}
$this.val(newValue);
} function keepSH2(obj, num ,maxlength) {
var $this = $(obj);
var v = $this.val();
var imposeNum = maxlength ? (maxlength+1) : 4;//限制小数点数量,默认为小数点后3位
if (isNaN(v)) {
var values = v.slice(0, -1);
if (isNaN(values)) {
values = ''
}
$this.val(values);
} else if (v.indexOf('.') != -1) {
if (v.split('.')[1].length == imposeNum) {
var values = v.slice(0, -1);
$this.val(values);
} else if (v.split('.')[1].length > imposeNum) {
$this.val('');
}
} else {
$this.val(v.replace(/\s|-/g, ""));
} var newValue = $this.val();
if (!isNaN(newValue) && newValue != '') {
if (newValue > num) {
newValue = num;
}
}
$this.val(newValue);
}
// 检查是否为手机号
function checkMobile(text) {
var myreg = /^(1+\d{10})$/;
return !myreg.test(text) ? false : true;
}
//仅输入中文,字母,数字
function unCharacter(v) {
return v.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')
}
//禁止特殊字符
function unSpecial(v) {
return v.replace(/[^u4e00-u9fa5w]/g,'')
}
// 用来判断对象是否为空
function isEmptyObject(e) {
var t;
for (t in e)
return !1;
return !0
}
//格式化日期:yyyy-MM-dd     
function formatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth() + 1;
var myweekday = date.getDate(); if (mymonth < 10) {
mymonth = "0" + mymonth;
}
if (myweekday < 10) {
myweekday = "0" + myweekday;
}
return (myyear + "-" + mymonth + "-" + myweekday);
} //获得某月的天数
function getMonthDays(myMonth) {
var monthStartDate = new Date(nowYear, myMonth, 1);
var monthEndDate = new Date(nowYear, myMonth + 1, 1);
var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
return days;
} //获得本季度的开始月份
function getQuarterStartMonth() {
var quarterStartMonth = 0;
if (nowMonth < 3) {
quarterStartMonth = 0;
}
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
}
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
}
if (nowMonth > 8) {
quarterStartMonth = 9;
}
return quarterStartMonth;
} //获得本周的开始日期
function getWeekStartDate() {
var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
return formatDate(weekStartDate);
} //获得本周的结束日期
function getWeekEndDate() {
var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
return formatDate(weekEndDate);
} //获得上周的开始日期
function getpreWeekStartDate() {
var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 7);
return formatDate(weekStartDate);
} //获得上周的结束日期
function getpreWeekEndDate() {
var weekEndDate = new Date(nowYear, nowMonth, nowDay + (-1 - nowDayOfWeek));
return formatDate(weekEndDate);
} //获得本月的开始日期
function getMonthStartDate() {
var monthStartDate = new Date(nowYear, nowMonth, 1);
return formatDate(monthStartDate);
} //获得本月的结束日期
function getMonthEndDate() {
var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
return formatDate(monthEndDate);
} //获得上月开始时间
function getLastMonthStartDate() {
var lastMonth2 = lastMonth;
var nowYear2 = nowYear;
if (nowMonth < lastMonth) {
var lastMonth2 = 11;
var nowYear2 = nowYear - 1;
}
var lastMonthStartDate = new Date(nowYear2, lastMonth2, 1);
return formatDate(lastMonthStartDate);
} //获得上月结束时间
function getLastMonthEndDate() {
var lastMonth2 = lastMonth;
var nowYear2 = nowYear;
if (nowMonth < lastMonth) {
var lastMonth2 = 11;
var nowYear2 = nowYear - 1;
}
var lastMonthEndDate = new Date(nowYear2, lastMonth2, getMonthDays(lastMonth));
return formatDate(lastMonthEndDate);
} //获得本季度的开始日期
function getQuarterStartDate() { var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
return formatDate(quarterStartDate);
} //获得本季度的结束日期
function getQuarterEndDate() {
var quarterEndMonth = getQuarterStartMonth() + 2;
var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
return formatDate(quarterStartDate);
} //计算当天 昨天 前天
function _getDay(day) {
var today = new Date(); var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day; today.setTime(targetday_milliseconds); //注意,这行是关键代码 var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
tMonth = doHandleMonth(tMonth + 1);
tDate = doHandleMonth(tDate);
return tYear + "-" + tMonth + "-" + tDate;
} function doHandleMonth(month) {
var m = month;
if (month.toString().length == 1) {
m = "0" + month;
}
return m;
}

/*获取选中的文字*/

var _getSelectedText = function() {

if (window.getSelection) {

return window.getSelection().toString();

} else if (document.getSelection) {

return document.getSelection();

} else if (document.selection) {

return document.selection.createRange().text;

}else{

return "";

}

}

js常用函数的封装的更多相关文章

  1. ecshop里提出来的js常用函数

    目录 Utils.js jquery.listTable.js 使用例子: ecshop里提出来的js常用函数 Utils.js /* $Id : utils.js 5052 2007-02-03 1 ...

  2. 总结js常用函数和常用技巧(持续更新)

    学习和工作的过程中总结的干货,包括常用函数.常用js技巧.常用正则表达式.git笔记等.为刚接触前端的童鞋们提供一个简单的查询的途径,也以此来缅怀我的前端学习之路. PS:此文档,我会持续更新. Aj ...

  3. js常用函数和常用技巧

    学习和工作的过程中总结的干货,包括常用函数.常用js技巧.常用正则表达式.git笔记等.为刚接触前端的童鞋们提供一个简单的查询的途径,也以此来缅怀我的前端学习之路. PS:此文档,我会持续更新. Aj ...

  4. 总结JS 常用函数

    希望本文总结的内容能给各位看官带来焕然一新的感觉.另外,如果你们有什么值得推荐的js技巧,欢迎在评论中补充,我可以收纳在本文中. PS:此文档会持续新增内容. Ajax请求 jquery ajax函数 ...

  5. js常用函数、书写可读性的js、js变量声明...

    1.Array类型函数 array.concat(item...) 函数功能:关联数组,实现数组相加功能,但并不影响原先数组,concat返回新数组. array.join(separator) 函数 ...

  6. js常用函数整理

    类型转换:parseInt\parseFloat\toString 类型判断:typeof;eg:if(typeof(var)!="undefined")\isNaN 字符处理函数 ...

  7. 【转】JS常用函数整合库 lutils

    lutils 此工具包是在 outils 的基础上,加上个人平时收集的代码片段进行的二次整合 outils的GitHub:https://github.com/proYang/outils/blob/ ...

  8. js常用函数汇总(不定期更新)

    1.图片按比例压缩 function setImgSize(){ var outbox_w=imgbox.width(), outbox_h=imgbox.height(); imgbox.find( ...

  9. js原生函数一些封装

    这是一些js原生封装的函数,主要是为了兼容IE浏览器,如下 获取css样式 function getStyle(ele, prop) { if(window.getComputedStyle) { r ...

随机推荐

  1. 25天javaweb基础

    第一天(html) 表格标签,超链接标签,图片标签,排版标签,列表标签 第二天(css) 表单标签 第三天(JS) js语法 定时器(系统对象的定时器setinterval,js的定时器seTimeo ...

  2. 【ZZ】堆和堆的应用:堆排序和优先队列

    堆和堆的应用:堆排序和优先队列 https://mp.weixin.qq.com/s/dM8IHEN95IvzQaUKH5zVXw 堆和堆的应用:堆排序和优先队列 2018-02-27 算法与数据结构 ...

  3. Hive学习笔记一

    1. Load的使用 //在1.x版本中定义long数据类型会报错(用bigint代替) create table t_load_stu(name string,age bigint) row for ...

  4. android 5.0安装应用冲突问题

    公司二款产品无法同时安装 为了查看原因 用adb命令安装((adb 命令要配置环境环境,path 盘符+adt-bundle-windows-x86-20140702\sdk\platform-too ...

  5. python之路——6

    王二学习python的笔记以及记录,如有雷同,那也没事,欢迎交流,wx:wyb199594 复习 增dic['age'] = 21 dic.setfault()删popcleardel popitem ...

  6. 几个常用的SQL 时间函数

    --当月第一天declare @startFirstDate datetimeset @startFirstDate=dateadd(dd,datediff(dd,0,getdate()),-day( ...

  7. 关于dict的formkeys方法注意

    使用容器中的元素生成k, v为统一值, 指向同一个内存地址 默认值指向同一个内存, 修改就全部修改 strvar = 'abcd' listvar = [] dictvar = {} dictvar ...

  8. C# DataReader

    //1 连接字符串 string connectionString = "server=127.0.0.1;integrated security=true;database=MSPetSh ...

  9. 修改IP和DNS的dos命令

    修改IP,掩码,网关命令: netsh interface ip set address "本地连接" static 192.168.3.188 255.255.255.0 192 ...

  10. HTML5和CSS3的一些学习记录

    1.引述块级文本的标签(blockquote): <blockquote cite="http://www.marktwainbooks.edu/"> <p> ...