上述與以下代碼相同:
function Circle(xPoint,yPoint,radius) {
?this.x = xPoint;
?this.y = yPoint;
?this.r = radius;
}
Circle.prototype.pi = Math.PI;
function Circle.prototype.area() {
?return this.pi*this.r*this.r;
}
//Circle.prototype.area = circleArea;
function getCircleArea(x,y,r) {
?aCircle = new Circle(x,y,r);
?return aCircle.area();
}
===========================================================
var Try = {
? these: function() {
??? var returnValue;
??? for (var i = 0; i < arguments.length; i++) {
????? var lambda = arguments[i];
????? try {
??????? returnValue = lambda();
??????? break;
????? } catch (e) {}
??? }
??? return returnValue;
? }
}
var Ajax = {
? getTransport: function() {
??? return Try.these(
????? function() {return new ActiveXObject('Msxml2.XMLHTTP')},
????? function() {return new ActiveXObject('Microsoft.XMLHTTP')},
????? function() {return new XMLHttpRequest()}
??? ) || false;
? },
? activeRequestCount: 0
}
================================================================
用原型方法(用prototype定義)在大量定義對象的時候會比較節省資源。也可以在系統的類(如String)上面附加新的方法。
function String.prototype.trim()
?{
?return? this.replace(/(^\s*)|(\s*$)/g, "");
?}
alert("? abcd? ".trim());
??? if (document.implementation && document.implementation.createDocument) {
??????? // This is the W3C standard way to do it
??????? return document.implementation.createDocument(namespaceURL,
????????????????????????????????????????????????????? rootTagName, null);
??? }
??? else { // This is the IE way to do it
??????? // Create an empty document as an ActiveX object
??????? // If there is no root element, this is all we have to do
??????? var doc = new ActiveXObject("MSXML2.DOMDocument");
??????? // If there is a root tag, initialize the document
??????? if (rootTagName) {
??????????? // Look for a namespace prefix
??????????? var prefix = "";
??????????? var tagname = rootTagName;
??????????? var p = rootTagName.indexOf(':');
??????????? if (p != -1) {
??????????????? prefix = rootTagName.substring(0, p);
??????????????? tagname = rootTagName.substring(p+1);
??????????? }
??????????? // If we have a namespace, we must have a namespace prefix
??????????? // If we don't have a namespace, we discard any prefix
??????????? if (namespaceURL) {
??????????????? if (!prefix) prefix = "a0"; // What Firefox uses
??????????? }
??????????? else prefix = "";
??????????? // Create the root element (with optional namespace) as a
??????????? // string of text
??????????? var text = "<" + (prefix?(prefix+":"):"") +? tagname +
??????????????? (namespaceURL
???????????????? ?(" xmlns:" + prefix + '="' + namespaceURL +'"')
???????????????? :"") +
??????????????? "/>";
??????????? // And parse that text into the empty document
??????????? doc.loadXML(text);
??????? }
??????? return doc;
??? }
};
function loadFromUrl(url) {
??? // Create a new document with the previously defined function
??? var xmldoc = XML.newDocument( );
??? xmldoc.async = false;? // We want to load synchronously
??? xmldoc.load(url);????? // Load and parse
??? return xmldoc;???????? // Return the document
}
function xmlToString(xmlDoc)
{
??? var?xmlString;
??? try
??? {
??????? if (navigator.appName == "Microsoft Internet Explorer")
??????? {
??????????? xmlString = xmlDoc.xml;
??????? }
??????? else
??????? {
??????????? xmlString = new XMLSerializer().serializeToString( xmlDoc );
??????? }
??? }
??? catch (e)
??? {
??????? xmlString = null;
??? }
??? return xmlString;
}
?
function stringToXMLDoc(str)
{
??? var xmlDoc = null;
??? try
??? {
??????? var xmlDOMObj = new ActiveXObject("Microsoft.XMLDOM");
??????? xmlDOMObj.async = false;
??????? xmlDOMObj.loadXML(str);
??????? xmlDoc = xmlDOMObj;
??? }
??? catch (e)
??? {
??????? try
??????? {
??????????? var domParser = new DOMParser;
??????????? xmlDoc = domParser.parseFromString(str, 'text/xml');
??????? }
??????? catch (e)
??????? {
??????????? xmlDoc = null;
??????? }
??? }
??? return xmlDoc;
?
}
function stringToXMLDoc(str) {
??? if (typeof DOMParser != "undefined") {
??????? // Mozilla, Firefox, and related browsers
??????? return (new DOMParser( )).parseFromString(text, "application/xml");
??? }
??? else if (typeof ActiveXObject != "undefined") {
??????? // Internet Explorer.
??????? var doc = XML.newDocument( );? // Create an empty document
??????? doc.loadXML(text);??????????? // Parse text into it
??????? return doc;?????????????????? // Return it
??? }
??? else {
??????? // As a last resort, try loading the document from a data: URL
??????? // This is supposed to work in Safari. Thanks to Manos Batsis and
??????? // his Sarissa library (sarissa.sourceforge.net) for this technique.
??????? var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
??????? var request = new XMLHttpRequest( );
??????? request.open("GET", url, false);
??????? request.send(null);
??????? return request.responseXML;
??? }
}
?this.cmpTabId = null;
?this.cmpTableId = null;
?this.funcTableId = null;
?this.currData = new Array();
?this.OUTLOOK = new Array();
?this.selectedArray = new Array();
?this.criterionArray = new Array();
??
?this.parseAllData = ComParserAllDataSub;
?this.sepArray = ComSepArraySub;
?this.initComTable = ComInitComTableSub;
?this.checkAllChild = ComCheckAllChildSub;
?this.checkParent = ComCheckParentSub;
?this.addselectedFC = ComAddselectedFCSub;
?this.generateXML = ComgenerateXMLSub;
?this.parserArray = ComparserArraySub;
?this.editFunc = ComEditFunc;
}
function InitAllSub(cmpId,allData,allDataEdit,tableType)
{
?if(allData == null || allData.length == 0)
?{
??_alertMsg += "This is no fap!";
??return;
?}
?var obj = new CE_CompanyObjSub(cmpId,allData,allDataEdit,tableType);
?cmSubArray.push(obj);
?obj.parseAllData();
?obj.sepArray();
?obj.initComTable();
?
?if(allDataEdit == null || allDataEdit.length == 0)
??return;
??
?obj.editFunc();
}
function ComParserAllDataSub()
{
?this.currData = this.allData;?
}
function ComSepArraySub()
{
????? var strCon=20;
?? TransStatus="Ready";
????? WorkWindow=top.work;
????? CommonData=top.commondata;
????? WorkWindowSet=top.bottomwork;
????? moduseq=-1;
????? grpseq=-1;
????? funcseq=-1;
????? modulen=0;
????? grplen=0;
????????
?????? for(i=0;i<this.currData.length;i++)
????????? {
??? varmoduId = this.currData[i][0];
??? varmodu = this.currData[i][1];
??? varfuncId = this.currData[i][2];
??? varfunc = this.currData[i][3];
??? if(bar)
??? ?varfuncDesc = this.currData[i][4];
???
???
?????? modulen=this.OUTLOOK.length;
?? ?????? for(m=0;m<modulen;m++)
?????? {
??????? if(this.OUTLOOK[m][0]==varmoduId + ":" + varmodu)
??????? {
?????????????????????? moduseq=m;
????????????????????? grplen=this.OUTLOOK[m].length;
????????????????????? for(n=1;n<grplen;n++)
???????????????????????? {
???????????????????????????? if(this.OUTLOOK[m][n][0]==varfuncId + ":" + varfunc + ":" + varfuncDesc)
???????????????????????????? {
??????????????????????????????? grpseq=n;
??????????????????????????????? break;
???????????????????????????? }
???????????????????????? }
???????? }
?????? }
??? if(moduseq==-1)
??? {
????????? this.OUTLOOK[modulen]=new Array();
????????? this.OUTLOOK[modulen][0]=varmoduId + ":" + varmodu;
????????? this.OUTLOOK[modulen][1]=new Array();
????????? this.OUTLOOK[modulen][1][0]=varfuncId + ":" + varfunc + ":" + varfuncDesc;
????????? moduseq=modulen;
????????? grpseq=1;
???? }
???? else
???? {
???????? if(grpseq==-1)
???????? {
??????????? grpseq=this.OUTLOOK[moduseq].length;
??????????? this.OUTLOOK[moduseq][grpseq]=new Array();
??????????? this.OUTLOOK[moduseq][grpseq][0]=varfuncId + ":" + varfunc + ":" + varfuncDesc;
?? ???????? }
???? }
??? moduseq=-1;
??? grpseq=-1;
?? }
??
}
?????????function low(imgLow){
???????????????low=imgLow;
???????????????clearInterval(highlighting);
????????????????lowlighting = setInterval("lowLight(low)",100);
?????????}
?????????function highlightit(img){
?????????????if(img.filters.alpha.opacity < 200) {
??????????????img.filters.alpha.opacity += 5;
?????????????}
?????????????//else if (window.highlighting)
??????????????//clearInterval(highlighting);
?????????}
?????????function lowLight(img) {
?????????????if(img.filters.alpha.opacity > 15)
????????????????????img.filters.alpha.opacity -= 5;
?????????????//else if (window.lowlighting)
??????????????//clearInterval(lowlighting);
?????????}
?????????網頁打開后,第一次鼠標移上去漸清晰,移走后也正常逐漸消失,都很正常。可當我再次把鼠標移到圖片上時,就沒有反應了,在移出圖片時JS報錯,說在<img />那行,對象不支持此屬性或方法。
????????調了好久也沒成功,特來向大家請教!