Skip to content

Instantly share code, notes, and snippets.

View titanew's full-sized avatar

Titane w titanew

View GitHub Profile
@titanew
titanew / gist:5624479
Last active December 17, 2015 14:29
判断字符串中是否还有重复的字母或者数字。
//一种用普通的字符串的方法,另外一种用正则,还是正则的扩展性高一点。。
//方法一:字符串方法
function ifRepeat(str) {
var ss = str;
for (var i = 0; i < ss.length; i++) {
var cha = ss.charAt(i);
var sub = ss.substring(0,i)+ss.substring(i+1);
if (sub.indexOf(cha)!=-1) {
console.log("有重复");
@titanew
titanew / gist:5624695
Last active December 17, 2015 14:29
简易ajax封装
var myAjax = {
// XMLHttpRequest IE7+, Firefox, Chrome, Opera, Safari ; ActiveXObject IE6, IE5
xhr: window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'),
get: function (url, callback) {
this.xhr.open('get', url);
this.onreadystatechange(callback, this.xhr);
this.xhr.send(null);
},
post: function (url, data, callback) {
this.xhr.open('post', url);
@titanew
titanew / gist:5624727
Last active December 17, 2015 14:29
将1-9共9个数字分成三组,分别组成3个三位数,使这三个三位数构成1:2:3
//1-9组成的三个三位数最小是123,最大是987。
//因为第三个是第一个的三倍,所以第一个数的最大值不可能大于329。
for (var j = 123; j < 330; j++) {
(function(e) {
var f = e * 2,
g = e * 3,
t = e.toString() + f + g,
rg = /0/g,
reg = /(?:^|)(\w{1}).*\1/g;
@titanew
titanew / gist:5628792
Created May 22, 2013 16:07
数组去重
Array.prototype.unique =
function() {
var a = [];
var l = this.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
if (this[i] === this[j])
j = ++i;
}
a.push(this[i]);
@titanew
titanew / gist:5648113
Created May 25, 2013 06:14
原生js获取YYYY-MM-DD格式日期
function getDate(){
var param = arguments,
date = new Date();
if(param.length==0){
return changeDateType(date);
}else if(param.length==1){
if(param[0].toString().indexOf("+")!="-1"){
var nowTime = date.getTime(),
preDate = param[0].substr(1,param[0].length-1),
preDateTime = Number(preDate)*24*60*60*1000;
@titanew
titanew / vimrc.vim
Created May 27, 2013 08:17 — forked from caiyili/vimrc
" ======================================================================================
" File : .vimrc
" Author : Wu Jie
" Last Change : 12/02/2009 | 12:02:28 PM | Wednesday,December
" Description :
" ======================================================================================
"/////////////////////////////////////////////////////////////////////////////
" exVim global settings
" NOTE: you should change to your own settings.
@titanew
titanew / gist:5660477
Last active December 17, 2015 19:29
表格斑马线
var zebra = function(klass) {
var table = document.getElementsByTagName("table");
var reg = new RegExp("(^|\s)" + klass + "(\s|$)");
// var reg = /(^|\s)main\-table(\s|$)/
for (var i = 0; i < table.length; i++) {
var cls = table[i].getAttribute("class");
if (reg.test(cls)) {
var tr = table[i].getElementsByTagName('tr');
for (var j = 1; j < tr.length; j++) {
if (j % 2 == 0) {
@titanew
titanew / gist:5696322
Last active December 18, 2015 00:28
小切换
(function(exports) {
var _control = document.getElementById("my-control");
var _scroll = document.getElementById('my-scroll');
var timer = null;
function addEvent(ele, type, fn) {
if (window.attachEvent) {
return ele.attachEvent("on" + type, fn)
} else if (window.addEventListener) {
return ele.addEventListener(type, fn, false)
@titanew
titanew / gist:5718565
Created June 6, 2013 00:55
about cookie
(function() {
function getCookie(name) {
var cookie = document.cookie;
var s = removeBlanks(cookie);
var pairs = s.split(";");
for (var i = 0; i < pairs.length; i++) {
var pairSplit = pairs[i].split("=");
if (pairSplit.length > 1 && pairSplit[0] == name) {
return pairSplit[1];
}
@titanew
titanew / gist:5726855
Last active December 18, 2015 04:39
小切换和小滚动。
(function($) {
//选项卡
$.fn.tab = function(options) {
var defaults = {
classname: "news-content",
speed: "100",
evt: "mouseover"
};
var opts = $.extend({}, defaults, options);