/*

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常用方法 备用的更多相关文章

  1. (2)Underscore.js常用方法

    目录 1.集合相关方法        1.1.数组的处理                map(循环,有返回值),将返回的值依次存入一个新的数组                each(循环,无返回值 ...

  2. js常用方法和检查是否有特殊字符串和倒序截取字符串

     js常用方法demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  3. JS常用方法封装

    迭代添加各种常用方法:项目中一定会有很多常用的方法,包括:取值,校验,等...... 获取 url 后的参数 function getQueryString(name) { var reg = new ...

  4. js常用方法

    若未声明,则都是js的方法 1.indexOf indexOf(str):默认返回字符串中第一次出现索引位置 的下标,没有则返回-1 indexOf(str,position):返回从position ...

  5. JS常用方法函数整理

    1.document.write("");为输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...

  6. JS常用方法函数

    document.write("");为 输出语句    2.JS中的注释为//    3.传统的HTML文档顺序是:document->html->(head,bod ...

  7. js常用方法收集

    JS获取地址栏制定参数值: //获取URL参数的值 function getUrlParam(name){ var reg = new RegExp("(^|&)"+ na ...

  8. js常用方法:

    1.将 "\/Date(1313572554031)\/" 转化为 “yyyy-MM-dd hh:mm:ss”字符串格式: //测试 var str = "\/Date( ...

  9. JS常用方法总结,及jquery异步调用后台方法实例

    //前台接收get参数值 function getQueryString(name) {            var queryStrings = window.location.search.sp ...

随机推荐

  1. 树莓派下ubuntu-mate中ssh服务的安装与开机后自启动

    ssh程序分为客户端程序openssh-client和服务端程序openssh-server. 如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序ubuntu是默认安装的.而如 ...

  2. Python9-From-CSS-day48

    1.form表单相关内容前后端有数据交互的时候用form表单form表单提交数据的几个注意事项: 1.所有获取用户输入的标签都必须放在form表单里面 2.action 控制着往哪里提交 3.inpu ...

  3. django之模型层

    1. ORM MVC或者MTV框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开发人员 ...

  4. proc的妙用

    今天在在公司做网络驱动开发测试时,随机包出现收包计数停止的现象,当时怀疑是DMA rx buffer不足导致,想通过对比收发包正常和收发包不正常是DMA相关寄存器的情况. 后跟踪代码,若在收发包里面增 ...

  5. poj 23565-Find a multiple

    Find a multiple The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each ...

  6. eeeeeeeeeee

    http://58.241.123.38/hot.cdn.baidupcs.com/file/91623e76f776475da9c3223cdac861f0?xcode=68983c005f6e3c ...

  7. spark 的createDstream和createDirectStream区别

    spark读取kafka数据流提供了两种方式createDstream和createDirectStream. 两者区别如下: 1.KafkaUtils.createDstream 构造函数为Kafk ...

  8. vim编辑器最简单使用方法

    i 输入模式 :q 不保存退出 :q! 强制退出 :wq 保存退出 j 下 k 上 h 左 l 右 gg start G end x 往后删 X 往前删 yy 复制行 p 粘贴 dd 剪切行 u 撤销 ...

  9. Python 有序字典简介

    Table of Contents 1. 有序字典-OrderedDict简介 1.1. 示例 1.2. 相等性 1.3. 注意 2. 参考资料 有序字典-OrderedDict简介 示例 有序字典和 ...

  10. Service IntentService区别 (面试)

    依然记得自己当初没有真正的工作经验的时候的日子,满北京跑,没有人要.妈的,现在就想问,还有谁!想想真解气.不提了. 曾经有个面试官问我service 和IntentService的区别.当时自己模模糊 ...