JavaScriptµÄÁíÍâÁ½Öּ̳лúÖÆ
1>zInherit£º
ËüÊÇÒ»¸ö×é¼þ£¬ÓÃÀ´¼Ì³Ð»ùÀàµÄËùÓÐÊôÐԺͷ½·¨¡£¸úÒÔǰ˵µ½µÄÔÐÍÁ´Ä£Ê½·Ç³£ÀàËÆ£¬Ö»²»¹ý±ÈÔÐ͸ü°²È«£¬Ò²ÎÞÐ뿼ÂDzÎÊýÎÊÌâ¡£ÏÂÃæ¿´¿´zInheritµÄÓ÷¨£º
¸Ã×é¼þÖÐÖ»ÓÐÁ½¸ö·½·¨£ºinheritfrom() instanceof()
function Polygon(iSides){
this.iSides = iSides;
if(typeof Polygon._initialized == "undefined"){
Polygon.prototype.getArea = function(){
return 0;
}
Polygon._initialized = true;
}
}
function Traingle(iHeight,iWidth){
Polygon.call(this,3);
this.iHeight = iHeight;
this.iWidth = iWidth;
if(typeof Traingle._initialized == "undefined"){
Traingle.inheritfrom(Polygon);
//ÉÏÐеÄЧ¹û¸úÔÀ´µÄÕâ¸ö·Ç³£ÀàËÆ
// Traingle.prototype = new Polygon();
Traingle.prototype.getArea = function(){
return 0.5*iHeight*iWidth;
}
Traingle._initialized = true;
}
}
var traingle = new Traingle(12,4);
alert(traingle.getArea());//24
Note:ÔÚÖ´ÐÐǰ±ØÐë¼ÓÔØzInherit.js
2>xbObjects.js
ËüÊÇÒ»¸ö¹¦ÄܸüÇ¿´óµÄ¼Ì³Ð»úÖÆ£¬³ýÁË¿ÉÒԼ̳лùÀàµÄÊôÐԺͷ½·¨Í⣬»¹¿ÉÒÔµ÷Óø¸ÀàµÄ·½·¨£¬ÔÚÖ´ÐÐǰҳ±ØÐëÔö¼Ó×é¼þxbObject.js.
¾ßÌåµÄ²½ÖèÈçÏ£º
µÚÒ»²½£º×¢²áÀࣨ_classes.registerClass("sub_class","base_class") _classes.register("sub_class")£©
µÚ¶þ²½£º¹¹Ô캯Êý£¬²¢ÔÚº¯ÊýÖж¨ÒåÀà(_classes.defineClass("class_name",prototypeFunction))
µÚÈý²½£ºÖ´ÐÐinit£¨£©·½·¨£¬¸Ã·½·¨µÄ²ÎÊý±ØÐë¸ú¹¹Ô캯ÊýµÄ²ÎÊýÆ¥Åä
µÚËIJ½£º¿ÉÒÔͨ¹ýparentMehtod("method_name",arguments)
<mce:script type="text/javascript"><!--
//Polygon
_classes.registerClass("Polygon"); //1
function Polygon(iSides){ //2
_classes.defineClass("Polygon",prototypeFunction);
this.init(iSides);//³õʼ»¯PolygonµÄËùÓÐÊôÐÔ//3
function prototypeFunction(){//4
Polygon.prototype.init = function(iSides){
this.parentMethod("init");
this.iSides
Ïà¹ØÎĵµ£º
×î¶ÌµÄÍ϶¯´úÂë
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script l ......
1.document.formName.item("itemName") ÎÊÌâ
˵ Ã÷:IEÏÂ,¿ÉÒÔʹÓÃdocument.formName.item("itemName")»òdocument.formName.elements ["elementName"];FirefoxÏÂ,Ö»ÄÜʹÓÃdocument.formName.elements["elementName"].
½â¾ö·½·¨:ͳһʹÓÃdocument.formName.elements["elementName"].
2.¼¯ºÏÀà¶ÔÏóÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔ ......
var docEle = function() {
return document.getElementById(arguments[0]) || false;
}
function cloDiv(){
var overlayID="overlay";
var msgID = "overlayMsg";
document.body.removeChild(docEle(overlayID));
document.body.removeChild(docEle(msgID));
}
function openNewDiv() {
......
1.document.formName.item("itemName") ÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓÃdocument.formName.item("itemName")»òdocument.formName.elements["elementName"];FirefoxÏÂ,Ö»ÄÜʹÓÃdocument.formName.elements["elementName"].
½â¾ö·½·¨:ͳһʹÓÃdocument.formName.elements["elementName"].
2.¼¯ºÏÀà¶ÔÏóÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓÃ() ......
1ÅжÏselectÑ¡ÏîÖÐ ÊÇ·ñ´æÔÚValue="paraValue"µÄItem
2ÏòselectÑ¡ÏîÖÐ ¼ÓÈëÒ»¸öItem
3´ÓselectÑ¡ÏîÖРɾ³ýÒ»¸öItem
4ɾ³ýselectÖÐÑ¡ÖеÄÏî
5ÐÞ¸ÄselectÑ¡ÏîÖÐ value="paraValue"µÄtextΪ"paraText"
6ÉèÖÃselectÖÐtext="paraText"µÄµ ......