随笔分类 - 源码解读
摘要:function bindEvent() { var obj = document.createElement("XXX"); obj.onclick = function () { } // obj = null;} 我们使用闭包时,可以将不需继续调用局部变量在父函数末尾置为null。
阅读全文
摘要://如何在返回的函数中绑定父函数的作用域thisfunction bound () { return function () { console.log(this); }.bind(this);} bound()();
阅读全文
摘要:function escapeHTML(n) { var t = document.createElement("div"), i = document.createTextNode(n); return t.appendChild(i), t.innerHTML}
阅读全文
摘要:var d = document.getElementById;var s = d("demo").innerHTML;alert(s);// IE 没有问题,其他浏览器必须指定上下文var d = document.getElementById;var s = d.call(window, "demo").innerHTMLalert(s);
阅读全文
摘要:一、概述客户端Javascript的存在,是为了使静态的Html页面变成可交互的Web应用。可以脚本化Html页面的内容是JavaScript的核心目的。二、选择文档元素1、getElementByID();每个文档的元素都可以赋一个在文档范围内唯一的id属性。在微软IE8之前的浏览器,该方法还会去匹配name属性,然后返回匹配的元素。2、getElementsByName();3、getElementsByTagName();可以在document和element上调用4、getElementByClassName();可以在document和element上调用5、querySelecto
阅读全文
摘要:var globalEval =function(data) { (window.execScript || function(data){ window.eval.call(window,data); })(data);}
阅读全文
摘要:Function.prototype.bind = function(b) { var a = this; return function() { a.apply(b, arguments) }};Function.prototype.once = function() { var b = false, a = this; return function() { if (b) { return } else { b = true; a.appl...
阅读全文
摘要:/* * This is an example build file that demonstrates how to use the build system for * require.js. * * THIS BUILD FILE WILL NOT WORK. It is referencing paths that probably * do not exist on your machine. Just use it as a guide. * * */({ // app顶级目录,非必选项。如果指定值,baseUrl则会以此为相对路径 appDir: "some/path.
阅读全文
摘要:// Zepto.js// (c) 2010-2013 Thomas Fuchs// Zepto.js may be freely distributed under the MIT license.;(function($, undefined){ var prefix = '', eventPrefix, endEventName, endAnimationName, vendors = { Webkit: 'webkit', Moz: '', O: 'o' }, document = window.document, tes
阅读全文
摘要:// Zepto.js// (c) 2010-2013 Thomas Fuchs// Zepto.js may be freely distributed under the MIT license.;(function($){ // Create a collection of callbacks to be fired in a sequence, with configurable behaviour // Option flags: // - once: Callbacks fired at most one time. // - memory:...
阅读全文
摘要:function checkPassword(username,password,callback){ var pwdHash; var queryStr = 'select * from user where username = ?'; db.query(queryStr,username,queryCallback); function queryCallback(err,result){ if(err) throw err; pwdHash = result['passw...
阅读全文
摘要:1. 如果没有firebug , 可以用firebug-lite.js 内嵌的调试方式。2. console.log 不是所有浏览器都支持console.log 在IE或者没有调试窗口的浏览器中,console.log会undefinedvar db = {switch:true}db.log = function(){ if(!this.switch) return ; if( typeof console == 'undefined' ) return ; var slice = Array.prototype.slice; var args = slice.cal...
阅读全文
摘要:$request = $.getJSON('test.php'); $request.done(process1); $request.done(process2); $request.always(process3); function process1() { console.log('process1:'); } function process2() { console.log('process2'); } function process3() { console.log('process3')...
阅读全文
摘要://已经把最外面的$ 保存到了内部。var _$ = window.$, _jQuery = window.jQuery,...noConflict: function( deep ) { window.$ = _$; //把最外面的$重新赋值 if ( deep ) { window.jQuery = _jQuery; } return jQuery; },window.jQuery = window.$ = jQuery;
阅读全文
摘要:<?php/** * Author: humanhuang * Date: 13-12-17 */header('Access-Control-Allow-Origin:*');header('Access-Control-Request-Method:GET,POST');echo "nice";$.get('http://10.24.66.6/human/www/1/animate/3/ajax.php',function(e){console.log(e);})
阅读全文
摘要:if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); } }
阅读全文
摘要:var Pubsub = (function (window) { window.handlers = {}; var o = { pub: function () { var args = Array.prototype.slice.call(arguments,0), event = args.shift(); var cbs = handlers[event]; if (cbs) { ...
阅读全文
浙公网安备 33010602011771号