随笔分类 -  javascript tips

摘要:// 上面的递归调用会发生每个函数都是一个栈,会生成一个不断堆叠的函数栈直到最后一个栈函数return后依次退出。 优化性能效率版 排序算法部分 paixu.js 阅读全文
posted @ 2017-02-03 15:37 wifix 阅读(1792) 评论(0) 推荐(0) 编辑
摘要:$('#sub').click(function () { var self = $(this); if( oneshotbtn(self,2000,'#01b637') ){ return false; } }); function oneshotbtn(btn_el,delay,color) { ... 阅读全文
posted @ 2016-10-30 13:52 wifix 阅读(1218) 评论(0) 推荐(0) 编辑
摘要:js for 循环 跳出多层循环 可见 return 会直接跳出多层循环,返回调用的方法外部原因: js里for是没有局部作用域的概念,方法才能一个局部作用域return将会跳出当前局部作用继续执行下面的方法 注意:1.这里for循环如果直接放在全局作用域下执行而不被一个方法包裹,将直接导致写在fo 阅读全文
posted @ 2016-09-02 17:55 wifix 阅读(98462) 评论(1) 推荐(0) 编辑
摘要:if(!phone){ alert('请输入您的手机号码!') return false; } var re = /^1\d{10}$/; if(!( re.test(phone) ) ){ alert('请输入正确的手机号码!'); return false; } var rexp = /[a-zA-Z0-9]/; if( !rexp.test(name) ){} // 匹配数字... 阅读全文
posted @ 2016-08-31 10:21 wifix 阅读(1647) 评论(0) 推荐(0) 编辑
摘要:var el = document.createElement('pre'); // 创建 元素 el.id = 'sss'; // 添加id document.body.appendChild(el); // 把它 加入到body的底部去 el = document.getElementById('sss'); // 访问dom 根据id得到... 阅读全文
posted @ 2016-08-25 18:21 wifix 阅读(830) 评论(0) 推荐(0) 编辑
摘要:fixIME(); function fixIME(){ scroll_y = 100; // 如果键盘弹起后 网页window对象的卷起小于此值,说明没有自动卷起 单位:px timer = 500; //focus事件中500ms后进行判断 因为调起输入法键盘本身会有一定时间的延时 max_sc 阅读全文
posted @ 2016-08-18 15:54 wifix 阅读(1966) 评论(0) 推荐(0) 编辑
摘要:css: .bg { width: 100%;height:auto; } .content{width:100%;min-height:100px;} html: <div id="img_bg"><img class="bg" src="/zhannew/statics/images/cdz/r 阅读全文
posted @ 2016-08-18 15:23 wifix 阅读(391) 评论(0) 推荐(0) 编辑
摘要://从1970年开始的毫秒数然后截取10位变成 从1970年开始的秒数 function timest() { var tmp = Date.parse( new Date() ).toString(); tmp = tmp.substr(0,10); return tmp; } js 时间戳 var ts = Date.parse(new Date()); // ts 得... 阅读全文
posted @ 2016-06-14 17:35 wifix 阅读(50523) 评论(0) 推荐(1) 编辑
摘要:jade语法: #{xxx} //嵌入数据 p= xxx //嵌入数据 p #{xx} //嵌入数据 标签 html // 翻译为 div#test // div.bb-dd // div#bb.aa.cc //也可以的,类似emmet的语法 #content .item // p 啊噢! // 啊噢! p | foo bar baz ... 阅读全文
posted @ 2016-05-24 16:08 wifix 阅读(980) 评论(0) 推荐(0) 编辑
摘要:js 设置url参数 js 移除url参数 阅读全文
posted @ 2016-05-23 16:06 wifix 阅读(459) 评论(0) 推荐(0) 编辑
摘要:function addLoadEvent(func) { var old_onload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else{ old_onload(); func(); ... 阅读全文
posted @ 2016-04-25 18:21 wifix 阅读(303) 评论(0) 推荐(0) 编辑
摘要:解决jquery与zepto等其它库冲突兼容的问题;(function ($) { }) (jQuery);;(function ($) { }) (Zepto); 在Bootstrap源码(具体请看《Bootstrap源码解析》)和其他jQuery插件经常看到如下的写法: +function ($ 阅读全文
posted @ 2016-04-25 09:47 wifix 阅读(774) 评论(0) 推荐(0) 编辑
摘要:可以的:test(); // 直接function 方式声明的函数可以直接调用,后声明function test(){}aa(); //error var 方式声明的函数需先声明后调用var aa = function(){} 参考: 因为闭包! 所以也可以这样做 JavaScript doesn' 阅读全文
posted @ 2016-04-07 14:39 wifix 阅读(452) 评论(0) 推荐(0) 编辑
摘要:js 执行时间function use_time(func) { var start = new Date().getTime(); console.log(start); func(); var end = new Date().getTime(); console.log(end); conso 阅读全文
posted @ 2016-04-06 22:49 wifix 阅读(1592) 评论(0) 推荐(0) 编辑
摘要:note:当页面内嵌入一个iframe实际上是在dom上新建了一个新的完整的window对象 iframe中取得主窗体 window.top (顶级窗口的window对象) window.parent (当前iframe的父窗体window) 多层嵌套的iframe window.parent.pa 阅读全文
posted @ 2016-04-01 11:11 wifix 阅读(11258) 评论(0) 推荐(0) 编辑
摘要:1.检测安卓,苹果和windows phone的手机 var ua = navigator.userAgent;var url;if(ua.match(/Windows\sPhone/i) !=null){ console.log('this is Windowsphone ');}else if( 阅读全文
posted @ 2016-03-24 17:32 wifix 阅读(1475) 评论(0) 推荐(0) 编辑
摘要:1.typeof 操作符 主要检测基础数据类型 note: javascript的函数属于对象类型,null属于object,null 被认为是对象的占位符,如果typeof的对象是正则表达式, 在Safari和Chrome中使用typeof的时候会返回"function",其他的浏览器返回的是ob 阅读全文
posted @ 2016-03-21 15:48 wifix 阅读(468) 评论(0) 推荐(0) 编辑
摘要:js函数的参数: js是弱类型的编程语言,调用函数时既不在乎函数的参数,也不在意参数的类型即便你定义的函数值接受两个参数,在调用这个函数时也未必一定要是两个参数。可以传递一个、三个甚至不传递参数,而解析器永远不会有什么怨言.之所以会这样,原因是ecmascript中的参数在内部是用一个数组来运行的。 阅读全文
posted @ 2016-03-21 11:30 wifix 阅读(298) 评论(0) 推荐(0) 编辑
摘要:通过这样,可以实现js的继承,可以通过prototype(原型来实现继承),也可以直接通过call方法来实现继承 apply方法和call方法作用一样,但由于apply方法会自动把一个数组作为一个一个的参数传入进去,所以,apply可以有一些更巧妙的用法 apply的特性应用如: 1. Math.m 阅读全文
posted @ 2016-03-14 10:47 wifix 阅读(260) 评论(0) 推荐(0) 编辑
摘要:1. $.fn.pluginName = function(opt){}就是为jquery的prototype定义了函数, 这样, 任何一个jquery对象都可以使用这个成员函数, 这种写法直观明了, 你只要知道的就是$.fn = jQuery.prototype = $.prototype   2 阅读全文
posted @ 2016-03-14 09:27 wifix 阅读(1413) 评论(0) 推荐(0) 编辑