ITeye博客

caniggia1986的博客

caniggia1986 · 共 37 篇文章

ie6 getElementById/getElementsByName bug

javascript:mctmp(0); in ie6: document.getElementsByName(nameValue) will return the element which id attribute equals to nameValue document.getElementById(idValue) will return the element which name attribute equals to idValue so prevent to use the same id and name attribute value in dom! var getEle…

2011-12-23 11:25 · javascript · 评论(0)

getElementsByAttribute

//属性选择符 //author:司徒正美 ref:http://www.cnblogs.com/rubylouvre/archive/2009/10/26/1590102.html //正则支持 tag[attrname ^\$\*\~\!=attrValue] var getElementsByAttribute = function(search) { var tag = /([\*a-za-z1-6]*)?(\[(\w+)\s*(\^|\$|\*|\||~|!)?=?\s*([\w\u00C0-\uFFFF\s\-_\.]+)?\])?/, node = arguments[1] |…

2011-12-23 11:09 · javascript · dom · 评论(0)

Node.contains

/* code ref http://www.cnblogs.com/rubylouvre/archive/2009/10/14/1583523.html IE有contains方法。如果A元素包含B元素,则返回true,否则false。唯一不支持这个方法的是firefox。 不过火狐支持compareDocumentPosition() 方法,这是W3C制定的方法,标准浏览器都支持。 它的使用形式与contains差不多,但返回的不是一个布尔值,而是一个很奇怪的数值,它是通过如下方式累加计算出来的: 二进制 数值 含义 000000 0 元素一致 000001 1 节点在不同的文档(或者一…

2011-12-23 10:28 · javascript · dom · 评论(0)

getElementsByClassName

//code ref http://www.cnblogs.com/rubylouvre/archive/2009/07/24/1529640.html //支持 多class搜索 ie:getElementsByClassName("classA classB") var getElementsByClassName = function (searchClass, node, tag) { var node = node || document; var tag = tag || "*"; if (document.getElementsByClassName) {//尽量用原生方法 v…

2011-12-23 09:57 · javascript · 评论(0)

javascript clone

ref

2011-12-21 10:09 · javascript · 评论(0)

jquery实现aop?

如果想重写jQuery某个方法又不想直接改源码,你可以这样 改写unique() (function($){ var _old = $.unique;//备份原始方法 $.unique = function(arr){ //如果是dom对象就使用原始方法 if (!!arr[0].nodeType){ return _old.apply(this,arguments); } else { //使用grep/inArray组合方法去重 return $.grep(arr,function(v,k){ return $.inArray(v,arr) === k; }); }};})(jQuery…

2011-12-15 22:31 · javascript · jquery · 评论(0)

一些比较好的jquery优化

1.选择:优先用#id,使用.class前面带上tag名称,多次操作是使用变量保存(或链式操作)。 2.sizzle:1.3后采用的选择器引擎采用‘自右向左’取代传统的‘自左向右’,右边选择器更加明确,比如 $('div.class span.class2'),因此在写选择器时需要考虑这点 3.绑定事件时用live()/delegate()取代bind() 4.操作dom时可以先取出dom->操作dom—>恢复到原来的位置 var theForm = $('#myForm'); var formParent = theForm.parent(); theForm.remove(); inpu…

2011-12-15 22:19 · jquery · 评论(0)

javascript正则表达式

2011-12-15 13:18 · javascript · regex · 评论(0)

jquery源码分析【转】

http://www.cnblogs.com/nuysoft/archive/2011/11/14/2248023.html http://www.cnblogs.com/fjzhou/

2011-12-14 09:31 · jquery · 评论(0)

深入理解Javascript之this关键字

this:在Javascript中,This关键字永远都指向函数(方法)的所有者. http://www.laruence.com/2009/09/08/1076.html 原型链和原型:The prototype is only used for properties inherited by objects/instances created by that function. The function itself does not use the associated prototype http://www.laruence.com/2010/05/13/1462.html 作用域…

2011-12-12 23:09 · javascript · 评论(0)

jQuery.globalEval()

//和eval()不同的是他用全局上下文(window)用于加载运行在全局范围的外部脚本 globalEval: function( data ) { if ( data && rnotwhite.test( data ) ) { //IE用execScript //标准用匿名函数使全局window作为上下文调用eval ( window.execScript || function( data ) { window[ "eval" ].call( window, data );//chrome一些版本里eval.call(window,data)无效 } )( data ); } } //…

2011-12-08 13:56 · javascript · jquery · 评论(0)

jQuery.parseXML()

parseXML: function(data, xml, tmp) { if (window.DOMParser) { //标准 IE9可以 tmp = new DOMParser(); xml = tmp.parseFromString(data, "text/xml"); } else { // IE xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = "false"; xml.loadXML(data); } tmp = xml.documentElement; if (!tmp || !tmp.nodeName || t…

2011-12-08 13:46 · javascript · jquery · xml · 评论(0)

jQuery.isWindow

// A crude way of determining if an object is a window isWindow: function( obj ) { return obj && typeof obj === "object" && "setInterval" in obj; } Here is how it works: 1. it detects if there is an object being returned 2. it detects if the object type is object 3. it sees if setInterval is a meth…

2011-12-08 13:28 · javascript · jquery · 评论(0)

javascript函数中变量的范围

var first = 'hi there'; var first = (function() { console.log("first", first); // undefined var first = "hello world"; })(); //相当于 var first = 'hi there'; var first = (function() { var first;//the variable declaration moved to the top console.log("first", first); // undefined var first = "hello wor…

2011-12-08 11:17 · javascript · 评论(0)

javascript string replace妙用

http://www.codebit.cn/javascript/javascript-replace.html String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(m,i){ return m+args[i]; }); }; console.log("{0} is {1}".format("hello","world")); hello is world 如果 replacement为函数,对于每一个匹配的子字符串,调用该函数时带有下面…

2011-12-08 09:29 · javascript · 评论(0)