参考 prototype.js 及网上资源.在项目中进行实战.
参考 prototype.js 及网上资源.在项目中进行实战.

一. 静态属性
下面是静态类里的方法,事实上,我们这里用属性,甚至是常量 更好一些.
None.gifvar InParamsClass =
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    //IE临时目录。
InBlock.gif    TempPath : function GetTempPath()
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        try
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            var WshShell = new ActiveXObject("WScript.Shell");  
InBlock.gif            var keyValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\Directory");  
InBlock.gif            var iPos = keyValue.indexOf('Content.IE');
InBlock.gif            return    keyValue.substring(0,iPos);
ExpandedSubBlockEnd.gif        }
InBlock.gif        catch(e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif           return  "c:\\";
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif    } ,
InBlock.gif    
InBlock.gif    TempFile : "" 
ExpandedBlockEnd.gif}
None.gif

在属性 TempPath  里,不能包含复杂的逻辑和返回值. 下面是用属性的表示方法:

None.gifvar InParamsClass =
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    //IE临时目录。
InBlock.gif    TempPath : "" ,
InBlock.gif    TempFile : "" 
ExpandedBlockEnd.gif}
None.gif
None.gifInParamsClass.TempPath =  GetTempPath() ;
None.gif
None.giffunction GetTempPath()
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    try
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        var WshShell = new ActiveXObject("WScript.Shell");  
InBlock.gif        var keyValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\Directory");  
InBlock.gif        var iPos = keyValue.indexOf('Content.IE');
InBlock.gif        return    keyValue.substring(0,iPos);
ExpandedSubBlockEnd.gif    }
InBlock.gif    catch(e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif       return  "c:\\";
ExpandedSubBlockEnd.gif    }
ExpandedBlockEnd.gif

调用 InParamsClass.OpenFile

二.利用钩子,查看打开模态窗口的地址
None.gif  // 在 IE 状态栏显示要打开的路径. yxh .
None.gifwindow.showModalDialog2=window.showModalDialog ;
None.gif
None.gifwindow.showModalDialog = function(a,b,c)
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    window.status = "路径:"  + a + "参数:" + c;
InBlock.gif    Log( "路径:"  + a + "参数:" + c ) ;
InBlock.gif    c = GetString(c) ;
InBlock.gif    c = trimStr(c) ;
InBlock.gif
InBlock.gif    c = RemoveValue( c,"status") ;
InBlock.gif    c = RemoveValue(c,"resizeble") ;
InBlock.gif    c = RemoveValue(c,"scroll") ;
InBlock.gif
InBlock.gif    b =GetString(b) ;
InBlock.gif    var retVal = window.showModalDialog2(a , b ,GetString(c) ) ;
InBlock.gif
InBlock.gif    return retVal ;
ExpandedBlockEnd.gif}
None.giffunction RemoveValue(InParams ,str)
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    var retVal = InParams ;
InBlock.gif    var num = InParams.indexOf(str) ;
InBlock.gif    if ( num >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        if ( num == InParams.indexOf(str + ":0" ) )
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            retVal =  InParams.substring(0,num) + InParams.substring( num + str.length + 2 , InParams.length) ;
ExpandedSubBlockEnd.gif        }
InBlock.gif        else if ( num == InParams.indexOf(str + ":no") )
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            retVal =  InParams.substring(0,num) + InParams.substring( num +str.length + 3 , InParams.length) ;
ExpandedSubBlockEnd.gif        }
InBlock.gif        
InBlock.gif        retVal = retVal.replace(";;",";") ;
ExpandedSubBlockEnd.gif    }
InBlock.gif    return retVal ;
ExpandedBlockEnd.gif}
None.gif
None.giffunction trimStr(str) 
ExpandedBlockStart.gifContractedBlock.gifdot.gif
InBlock.gif     var re = /\s*(\S[^\0]*\S)\s*/; 
InBlock.gif     re.exec(str); 
InBlock.gif     return RegExp.$1; 
ExpandedBlockEnd.gif}
None.gif
None.giffunction GetString(str)
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    if ( str == null || str == undefined ) return "" ;
InBlock.gif    else return str ;
ExpandedBlockEnd.gif}
None.gif
None.giffunction Log(str)
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    var  fso  =  new  ActiveXObject("Scripting.FileSystemObject");   
InBlock.gif    var log = fso.OpenTextFile("C:\\Inetpub\\wwwroot\\log.txt", 8  );
InBlock.gif    var dt = new Date() ;
InBlock.gif    log.WriteLine( dt.toLocaleTimeString()  + " " +  str );  
InBlock.gif    log.Close();  
ExpandedBlockEnd.gif}


调用: window.showModalDialog("a.htm") ;

三. 类型转换:

定义一个Array可以这样:
    var m_GridMenu = new Array (
    {"text" :"打开信息dot.gif" ,    "img": "../images/open.gif" ,       "action" :"post" ,      "subMenuControlID":"gridMenu1"} ,
    {"text" :"-" ,              "img": "../images/open.gif" ,       "action" :"post"} ,
    {"text" :"标记为已读" ,     "img": "../images/readMail.gif" ,   "action" :"markRead"} ,
    {"text" :"标记为未读" ,     "img": "../images/unreadMail.gif" , "action" :"markUnread"}

如果把 Array 构造函数里面的内容,定义在别的地方, 但是,我的程序要提供另一个方式,就是在程序一个地方存储这个 Array 对象的内容(element.innerHTML ),在脚本的其它地方操作它. 这里用到了一个小技巧:

                var arrayItems ;
                eval( "arrayItems = new Array( " + element.innerHTML + ") ;" ) ;
JavaScript 与面向对象实战._其他_138   作者:NewSea     

  如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。