js常用方法 备用
/*
function obj$(id) 根据id得到对象
function val$(id) 根据id得到对象的值
function trim(str) 删除左边和右边空格
function ltrim(str) 删除左边空格
function rtrim (str) 删除右边空格
function isEmpty(str) 字串是否有值
function equals(str1, str2) js判断比较两字符串是否相等
function equalsIgnoreCase(str1, str2) js判断忽略大小写比较两个字符串是否相等
function isChinese(str) js判断判断是否中文
function isEmail(strEmail) js判断是否电子邮件
function isImg(str) js判断是否是一个图片格式的文件jpg|jpeg|swf|gif
function isInteger(str) js判断是否是一个整数
function isFloat js判断是否是一个浮点数
function isPost(str) js判断是否邮编(1位至6位
function isMobile(str) js判断是否是手机号
function isPhone(str) js判断是否是电话号码必须包含区号,可以含有分机号
function isQQ(str) js判断是否合法的QQ号码
function isIP(str) js判断是否是合法的IP
function isDate(str) js判断是否日期类型(例:2005-12-12)
function isIdCardNo(idNumber) js判断是否是合法的***号
*/
function obj$(id)
{
return document.getElementByIdx(id);
}
function val$(id)
{
var obj = document.getElementByIdx(id);
if(obj !== null)
{
return obj.value;
}
return null;
}
function trim(str)
{
return str.replace(/(^\s*)|(\s*$)/g, '');
}
function ltrim(str)
{
return str.replace(/^\s*/g,'');
}
function rtrim(str)
{
return str.replace(/\s*$/,'');
}
function isEmpty(str)
{
if(str != null && str.length > 0)
{
return true;
}
return false;
}
function equals(str1, str2)
{
if(str1 == str2)
{
return true;
}
return false;
}
function equalsIgnoreCase(str1, str2)
{
if(str1.toUpperCase() == str2.toUpperCase())
{
return true;
}
return false;
}
function isChinese(str)
{
var str = str.replace(/(^\s*)|(\s*$)/g,'');
if (!(/^[\u4E00-\uFA29]*$/.test(str)
&& (!/^[\uE7C7-\uE7F3]*$/.test(str))))
{
return false;
}
return true;
}
function isEmail(str)
{
if(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str))
{
return true
}
return false;
}
function isImg(str)
{
var objReg = new RegExp("[.]+(jpg|jpeg|swf|gif)$", "gi");
if(objReg.test(str))
{
return true;
}
return false;
}
function isInteger(str)
{
if(/^-?\d+$/.test(str))
{
return true;
}
return false;
}
function isFloat(str)
{
if(/^(-?\d+)(\.\d+)?$/.test(str)
{
return true;
}
return false;
}
function isPost(str)
{
if(/^\d{1,6}$/.test(str))
{
return true;
}
return false;
}
function isMobile(str)
{
if(/^1[35]\d{9}/.test(str))
{
return true;
}
return false;
}
function isPhone(str)
{
if(/^(0[1-9]\d{1,2}-)\d{7,8}(-\d{1,8})?/.test(str))
{
return true;
}
return false;
}
function isQQ(str){
if(/^\d{5,9}$/.test(str))
{
return true;
}
return false;
}
function isIP(str){
var reg = /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
if(.test(str))
{
return true;
}
return false;
}
function isDate(str)
{
var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
if(reg.test(str))
{
return true;
}
return false;
}
function isIdCardNo(idNumber)
{
var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
var varArray = new Array();
var lngProduct = 0;
var intCheckDigit;
var idNumber.length = ;
if ((idNumber.length != 15) && (idNumber.length != 18))
{
return false;
}
for(i=0;i<idNumber.length;i++)
{
varArray[i] = idNumber.charAt(i);
if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17))
{
return false;
}
else if (i < 17)
{
varArray[i] = varArray[i]*factorArr[i];
}
}
if (idNumber.length == 18)
{
var date8 = idNumber.substring(6,14);
if (checkDate(date8) == false)
{
return false;
}
for(i=0;i<17;i++)
{
lngProduct = lngProduct + varArray[i];
}
intCheckDigit = 12 - lngProduct % 11;
switch (intCheckDigit)
{
case 10:
intCheckDigit = 'X';
break;
case 11:
intCheckDigit = 0;
break;
case 12:
intCheckDigit = 1;
break;
}
if (varArray[17].toUpperCase() != intCheckDigit)
{
return false;
}
}
else
{
var date6 = idNumber.substring(6,12);
if (checkDate(date6) == false)
{
return false;
}
}
return true;
}
/**
*函数:按百分比获得客户端宽度
*/
function getWidth(percent) {
return document.body.clientWidth * percent;
} /**
*浏览器验证
*/
function checkBrowser() {
this.ver = navigator.appVersion
this.dom = document.getElementById ? 1 : 0
this.ie12 = (this.ver.indexOf("MSIE 12") > -1 && this.dom) ? 1 : 0;
this.ie11 = (this.ver.indexOf("MSIE 11") > -1 && this.dom) ? 1 : 0;
this.ie10 = (this.ver.indexOf("MSIE 10") > -1 && this.dom) ? 1 : 0;
this.ie9 = (this.ver.indexOf("MSIE 9") > -1 && this.dom) ? 1 : 0;
this.ie8 = (this.ver.indexOf("MSIE 8") > -1 && this.dom) ? 1 : 0;
this.ie7 = (this.ver.indexOf("MSIE 7") > -1 && this.dom) ? 1 : 0;
this.ie6 = (this.ver.indexOf("MSIE 6") > -1 && this.dom) ? 1 : 0;
this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom) ? 1 : 0;
this.ie4 = (document.all && !this.dom) ? 1 : 0;
this.ns5 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
this.ns4 = (document.layers && !this.dom) ? 1 : 0;
this.mac = (this.ver.indexOf('Mac') > -1) ? 1 : 0;
this.ope = (navigator.userAgent.indexOf('Opera') > -1);
this.ie = (this.ie12 || this.ie11 || this.ie10 || this.ie9 || this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4)
this.ns = (this.ns4 || this.ns5)
this.bw = (this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)
this.nbw = (!this.bw)
return this;
}
/**
* 格式化json日期格式,将其转化为正常日期格式
*/
function formatterDate(jsondate) {
var beginIndex = jsondate.indexOf("(") + 1;
var endIndex = jsondate.indexOf(")");
var birthdayDateNum = jsondate.substring(beginIndex, endIndex);
var date = new Date(parseInt(birthdayDateNum, 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minits = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); //2011-12-20 06:35:05.000
var resultdate = date.getFullYear() + "-" + month + "-" + currentDate + ' ' + hours + ":" + minits + ":" + seconds;
//+ ".000";
return resultdate;
} /**
* 格式化日期
*/
function formatterShortDate(jsondate) {
var beginIndex = jsondate.indexOf("(") + 1;
var endIndex = jsondate.indexOf(")");
var birthdayDateNum = jsondate.substring(beginIndex, endIndex);
var date = new Date(parseInt(birthdayDateNum, 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//2011-12-20
var resultdate = date.getFullYear() + "-" + month + "-" + currentDate
//+ ".000";
return resultdate;
}
js常用方法 备用的更多相关文章
- (2)Underscore.js常用方法
目录 1.集合相关方法 1.1.数组的处理 map(循环,有返回值),将返回的值依次存入一个新的数组 each(循环,无返回值 ...
- js常用方法和检查是否有特殊字符串和倒序截取字符串
js常用方法demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
- JS常用方法封装
迭代添加各种常用方法:项目中一定会有很多常用的方法,包括:取值,校验,等...... 获取 url 后的参数 function getQueryString(name) { var reg = new ...
- js常用方法
若未声明,则都是js的方法 1.indexOf indexOf(str):默认返回字符串中第一次出现索引位置 的下标,没有则返回-1 indexOf(str,position):返回从position ...
- JS常用方法函数整理
1.document.write("");为输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...
- JS常用方法函数
document.write("");为 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,bod ...
- js常用方法收集
JS获取地址栏制定参数值: //获取URL参数的值 function getUrlParam(name){ var reg = new RegExp("(^|&)"+ na ...
- js常用方法:
1.将 "\/Date(1313572554031)\/" 转化为 “yyyy-MM-dd hh:mm:ss”字符串格式: //测试 var str = "\/Date( ...
- JS常用方法总结,及jquery异步调用后台方法实例
//前台接收get参数值 function getQueryString(name) { var queryStrings = window.location.search.sp ...
随机推荐
- ecshop里提出来的js常用函数
目录 Utils.js jquery.listTable.js 使用例子: ecshop里提出来的js常用函数 Utils.js /* $Id : utils.js 5052 2007-02-03 1 ...
- python3 练习题100例 (十三)
题目十三:将一个正整数分解质因数.例如:输入60,打印出60=2*2*3*5. #!/usr/bin/env python3 # -*- coding: utf-8 -*- ""& ...
- has value '1.8', but '1.7' is required
使用java7,自己又想在空闲时间学一些java8的新特性,故在安装完1.7之后又安装了1.8 eclispe在启动时报’has value ‘1.8’,but’1.7’ is required’的错 ...
- git初次建立远程仓库问题
git "Could not read from remote repository.Please make sure you have the correct access rights. ...
- sql中over的用法
over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用.其参数:over(partition by columnname1 order by c ...
- WPF实现QQ群文件列表动画(一)
QQ群大家都用过,先看下目前QQ的群文件列表容器的效果: 细心点大家就会发现,这玩意收缩和展开是带动画的,并不是很僵硬地直接收缩或者直接展开,毫无疑问,如果用WPF实现这样的效果,这里的最佳控件是Ex ...
- Linux设置运行core dump
系统配置vim /etc/sysctl.conf kernel.core_uses_pid = kernel.core_pattern = %e-core-%p-%t sysctl -p检查有没有生效 ...
- JSP自定义tag控件标签
JSP支持自定tag的方法,那就是直接讲JSP代码保存成*.tag或者*.tagx的标签定义文件.tag和tagx文件不仅支持经典jsp代码,各种标签模版代码,还支持xml样式的jsp指令代码. 按照 ...
- easyui datagrid复选框控制单选
使用easyui datagrid的时候,由于对数据表格操作太多,并且有单选和多选功能因此采用复选框.但是在单选的状态,使用CheckOnSelect和singleselect时发现,页面有明显延迟, ...
- 排查和处理一台被攻击的linux系统及其事后分析
11:40 2018/3/16 发现最近几天服务器流量异常的大,检查了系统命令发现命令最近的修改时间很近,检查dns配置也发现了异常的dns服务器地址. 考虑到事态的严重性,铲掉这个系统重新搭建. 事 ...