javascriptÉè¼ÆÄ£Ê½_µÚ¶þ²¿·Ö_Á´Ê½µ÷ÓÃ
Á´Ê½µ÷ÓÃÊÇÒ»¸öÓï·¨ÕÐÊý.°üº¬Á½¸ö²¿·Ö:
1.Ò»¸ö´´½¨HTMLÔªËØµÄ¶ÔÏóµÄ¹¤³§
2.¶ÔÕâ¸öHTMLÔªËØÖ´ÐеIJÙ×÷µÄ·½·¨
[¸öÈËÀí½â:½«HTMLÔªËØ°ü×°³É¶ÔÏó,ÔÚ¶ÔÏóÉÏÌí¼Ó·½·¨(ÖØµãÔÚreturn this)]
¹¹ÔìÆ÷
(function(){
//Use a private class
function _$(els){
this.elements = [];
for(var i=0; i<els.length; i++){
var element = els[i];
if(typeof element === "string"){
element = document.getElementById(element);
}
this.elements.push(element);
}
}
//
_$.prototype = {
each : function(fn){
for(var i=0; i<this.elements.length; i++){
fn.call(this,this.elements[i]);
}
return this;
},
setStyle : function(prop,val){
this.each(function(el){
el.style[prop] = val;
});
return this;
},
show : function(){
var that = this;
this.each(function(el){
that.setStyle("display","bloc");
});
return this;
},
addEvent : function(type,fn){
var add = function(el){
if(window.addEventListener){
el.addEventListener(type,fn,false);
}
else if(window.attachEvent){
el.attachEvent("on"+type,fn);
}
}
this.each(function(el){
add(el);
})
return this;
}
};
//the public interface remains the same
window.$ = function(){
return new _$(arguments);
}
})()
ʹÓûص÷´ÓÖ§³ÖÁ´Ê½µ÷Óõķ½·¨»ñÈ¡Êý¾Ý
Á´Ê½µ÷ÓúÜÊʺÏÓÚ¸³ÖµÆ÷·½·¨,µ«¶ÔÓÚȡֵÆ÷·½·¨,Äã¿ÉÄÜ»áÏ£ÍûËüÃÇ·µ»ØÄãÒªµÄÊý¾Ý¶ø²»ÊÇ·µ»Øthis.
window.API2 = window.API2 || function(){
var name = "hell";
this.setName = function(newName){
name = newName;
return this;
};
this.getName = function(callback){
callback.call(this,name);
return this;
}
};
var o2 = new API2;
o2.getName(console.log).setName("Menw").getName(console.log);
Ïà¹ØÎĵµ£º
µ¥Ìåģʽ
Óŵã:°Ñ´úÂë×éÖ¯µÃÒ»Ö²¢¸ôÀë,¸üÈÝÒ×ÔĶÁºÍά»¤,Ìá¸ßÎȶ¨ÐÔ;ÓÃÓÚÓÅ»¯,ÌáÉýÐÔÄÜ
ȱµã:¿Éµ¼ÖÂÇ¿ñîºÏ
5.1 µ¥ÌåµÄ»ù±¾½á¹¹
var Singleton = {
attribute1 : true,
attribute2 : 10,
method1 : function(){},
method2 : function(){}
};
Ñϸñ°´¶¨ÒåÀ´Ëµ,C1²»ÊÇÒ»¸öµ¥Ìå,ÒòΪËü²»ÊÇÒ»¸ö¿ÉʵÀ ......
optionsÊý×é
¡¡¡¡¸ÃÊý×éÊÇselect¶ÔÏóµÄÒ»¸öÊôÐÔ,¼´Ñ¡Ôñ¿òÖеÄËùÓÐÑ¡Ïî(<OPTION>)µÄÒ»¸öÁÐ±í¡£
¡¡¡¡ÊôÐÔ
¡¡¡¡defaultSelected Ñ¡ÏîÁбíÖеÄȱʡѡÏî
¡¡¡¡index Ñ¡ÏîÁбíÖÐijѡÏîµÄË÷ÒýλÖÃ
¡¡¡¡length Ñ¡ÏîÁбíÖеÄÑ¡ÏîÊý(<OPTIONS>)
¡¡¡¡name Ñ¡ÏîÁбíµÄÃû×Ö(NAMEÌØÐÔ)
¡¡¡¡selected ±íÊ¾Ñ ......
//µÚÒ»ÖÖ¹¹Ôì·½·¨: new Object()
var a = new Object();
a.x = 1, a.y = 2;
//µÚ¶þÖÖ¹¹Ôì·½·¨: ¶ÔÏóÖ±½ÓÁ¿
var b = {x:1,y:b};
//µÚÈýÖÖ¹¹Ôì·½·¨: ¶¨ÒåÀàÐÍ
function Point(x,y)
{
......
±íµ¥µÄÑéÖ¤ÔÚʵ¼ÊµÄ¿ª·¢µ±ÖÐÊǼþºÜ·³ËöÓÖÎÞȤµÄÊÂÇé
½ñÌìÔÚ×öÒ»¸öСÏîÄ¿µÄʱºò,ÐèÒªJSÑéÖ¤,ѰÕÒµ½Ò»¸ö±È½ÏºÃµÄ¶«Î÷
µØÖ·ÈçÏÂ:
http://blog.csdn.net/goodfunman/archive/2005/10/21/513338.aspx
http://blog.csdn.net/yhl_621/archive/2006/03/04/615273.aspx
http://blog.csdn.net/NetDreamwing/archive/2004/1 ......
JavaScriptÎĵµ¶ÔÏó(DOM)
navigator
screen
window
history
location
frames[]; Frame
document
anchors[]; links[]; Link
applets[]
embeds[]
forms[]; Form
Button
Checkbox
elements[]; Element
Hidden
Password
Radio
Reset
Select
options[]; Option
Submit
Text
......