Skip to content

Instantly share code, notes, and snippets.

@tangyangzhe
tangyangzhe / gist:4bc6312f54197196a0d5
Created July 1, 2014 06:14
Serialize Form to JSON
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
var guid = function() {
var S4 = function() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
};
@tangyangzhe
tangyangzhe / 12306.user.js
Created December 11, 2012 03:01 — forked from quietlynn/12306.user.js
12306 Auto Query => A javascript snippet to help you book ticket
/*
12306 Auto Query => A javascript snippet to help you book tickets online.
Copyright (C) 2011-2012 Jingqin Lynn
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes Sizzle.js
@tangyangzhe
tangyangzhe / gist:4256645
Created December 11, 2012 07:49
js拖动
window.onload = function () {
drag(document.getElementById('drag'), [200, 400, 30, 300]);
};
function drag(o, r) {
o.firstChild.onmousedown = function () {
return false;
};
o.onmousedown = function (a) {
o.style.cursor = 'move';
@tangyangzhe
tangyangzhe / gist:4276560
Created December 13, 2012 14:01
javascript模块模式实现
// http://dancewithnet.com/2007/12/04/a-javascript-module-pattern/
<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/utilities/utilities.js"></script>
<ul id="myList">
<li class="draggable">一项</li>
<li>二项</li>
<li class="draggable">三项</li>
</ul>
<script>
YAHOO.namespace("myProject");
YAHOO.myProject.myModule = function () {

百度:Tangram

基本上就是个百度版jQuery,2.0版本使用链式API,更像了。
配套的还有UI库Magic和模版引擎BaiduTemplate(和ejs很像)

腾讯:JX

理念在介绍里面写的很详细,代码清晰,注释丰富,可读性很好,但只有文档没有实例。
比较传统的大块头框架,本质上来说还是一堆工具方法和对象的堆积,提供了很基本的模块化的开发方式,但没有模块间的依赖关系支持。

@tangyangzhe
tangyangzhe / gist:4282047
Created December 14, 2012 02:27
js尾部调用堆栈溢出demo
function isEven(number) {
if (number === 0) {
return true;
}
else {
return isOdd(number - 1);
}
}
function isOdd(number) {
@tangyangzhe
tangyangzhe / gist:6120477
Created July 31, 2013 08:53
js取消浏览器双击选中的文本
function clearSelection() {
if(document.selection && document.selection.empty) {
document.selection.empty();
} else if(window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}
@tangyangzhe
tangyangzhe / gist:6305895
Last active December 21, 2015 12:29
PHP使用PDO操作MySQL
function getConnection() {
$dbhost="127.0.0.1";
$dbuser="root";
$dbpass="root";
$dbname="cellar";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
@tangyangzhe
tangyangzhe / gist:6306188
Created August 22, 2013 11:45
提交JSON格式数据到服务端
/* 前端JS代码 */
function addWine() {
console.log('addWine');
$.ajax({
type: 'POST',
contentType: 'application/json',
url: rootURL,
dataType: "json",
data: formToJSON(),
success: function(data, textStatus, jqXHR){