This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 这里把符合以下条件的对象称为伪数组 | |
* 1,具有length属性 | |
* 2,按索引方式存储数据 | |
* 3,不具有数组的push,pop等方法 | |
* | |
*/ | |
//将伪数组转换成数组,ps:已测试IE6-10、chrome、Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @function: 通过a标签解析url标签 | |
* @param:url url参数是字符串,解析的目标 | |
通过IE6-9 chrome Firefox测试 | |
* | |
*/ | |
function parseURL(url) { | |
//创建一个a标签 | |
var a = document.createElement('a'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @function:generateRandomAlphaNum->生成随机的字符串 | |
* @param:len->生存随机字符串的长度 | |
* @tdd->IE6-9 chrome Firefox通过测试 | |
* | |
*/ | |
function generateRandomAlphaNum(len) { | |
var rdmString = ""; | |
//toSting接受的参数表示进制,默认为10进制。36进制为0-9 a-z | |
for (; rdmString.length < len; rdmString += Math.random().toString(36).substr(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @desccrition: 对String类型去除空格的拓展 | |
* @dir : 被去除空格所在的位置 | |
* @test: ie6-9 chrome firefox | |
*/ | |
String.prototype.trim = function(dir){ | |
switch (dir) { | |
case 0 : //去左边的空格 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @descrition: 对字符串进行截取,包括普通字符和中文字符 | |
* @param : str ->待截取的字符串 | |
* @param : len ->要截取的长度 | |
* | |
* 比如cutstr('hello',2)->he... cutstr("您好呀",4)->您好... | |
* 优先选择后台进行字符串截取,后css截取,最后js截取 | |
*/ | |
var cutstr = function(str, len) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @descition: 倒计时的一段脚本。 | |
* @param:deadline ->截止日期 符合日期格式,比如2012-2-1 2012/2/1等有效日期。 | |
* @return -> 截止的天数、小时、分钟、秒数组成的object对象。 | |
*/ | |
function getCountDown(deadline) { | |
var activeDateObj = {}, | |
currentDate = new Date().getTime(), //获取当前的时间 | |
finalDate = new Date(deadline).getTime(), //获取截止日期 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 更新: | |
// 05.27: 1、保证回调执行顺序:error > ready > load;2、回调函数this指向img本身 | |
// 04-02: 1、增加图片完全加载后的回调 2、提高性能 | |
/** | |
* 图片头数据加载就绪事件 - 更快获取图片尺寸 | |
* @version 2011.05.27 | |
* @author TangBin(PS:我不是作者,我只是代码的搬运工) | |
* @see http://www.planeart.cn/?p=1121 | |
* @param {String} 图片路径 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @descrition : 该函数的功能是判断转入的参数是否为数字类型。 | |
* @param->o : 传入的参数,参数可以为任何类型。 | |
* @return: true表示为数字,false为非数字 | |
* | |
*/ | |
var isNumber = function(o) { | |
return !isNaN(o); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @descrition: 测试给定的参数是否全部为中文字符,如"中test"不会通过 。 | |
* @param->str : 传入的参数,类型为字符串。 | |
* @return : true表示全部为中文,false为不全是中文,或没有中文。 | |
* | |
*/ | |
var isChinese = function (str) { | |
var pattern = /^[\u0391-\uFFE5]+$/g; | |
return pattern.test(str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @Dependence : https://gist.github.com/hehongwei44/3e167cfcda47d4c8051a#file-extendstringprototype-js | |
* @description : 判断输入的参数是否为空 | |
* @return : true表示为输入参数为空 | |
* | |
*/ | |
var isEmpty = function (str) { | |
//空引用 空字符串 空输入 | |
return str == null || typeof str == "undefined" || str.trim() == "" ? true : false; |
OlderNewer