JS动态给元素添加事件处理代码

来源:互联网 发布:linux如何卸载jenkins 编辑:程序博客网 时间:2024/05/16 18:51
// The default code is a com class (inherited from linb.Com)Class('App', 'linb.Com',{    // Ensure that all the value of "key/value pair" does not refer to external variables    Instance:{        // To initialize instance(e.g. properties)        initialize : function(){            // To determine whether or not the com will be destroyed, when the first UI control be destroyed            this.autoDestroy = true;            // To initialize properties            this.properties = {};        },        // To initialize internal components (mostly UI controls)        // *** If you're not a skilled, dont modify this function manually ***        iniComponents : function(){            // [[code created by jsLinb UI Builder            var host=this, children=[], append=function(child){children.push(child.get(0))};                        append(                (new linb.UI.Layout)                .setHost(host,"ctl_layout4")                .setItems([{"id":"before", "pos":"before", "min":10, "size":150, "locked":false, "folded":false, "hidden":false, "cmd":true}, {"id":"main", "min":10}])                .setType("horizontal")            );                        host.ctl_layout4.append(                (new linb.UI.Panel)                .setHost(host,"divreport")                .setZIndex(1)                .setCaption("grid++report在LoonBoo Ajax中的使用")            , 'main');                        host.ctl_layout4.append(                (new linb.UI.SButton)                .setHost(host,"btnopenreport")                .setLeft(10)                .setTop(40)                .setWidth(80)                .setCaption("打开报表")                .onClick("_btnopenreport_onclick")            , 'before');                        return children;            // ]]code created by jsLinb UI Builder        },        // Give a chance to load other com        iniExComs : function(com, threadid){        },        // Give a chance to determine which UI controls will be appended to parent container        customAppend : function(parent, subId, left, top){            // "return false" will cause all the internal UI controls will be added to the parent panel            return false;        },        // This instance's events        events : {},        _ctl_sbutton1_onclick : function (profile, e, src, value) {            var uictrl = profile.boxing();            linb.alert("hi","I'm " + uictrl.getAlias());        },        _btnopenreport_onclick : function(profile,e,src,value){            var ns = this, uictrl = profile.boxing();            ns.divreport.append('<OBJECT classid="CLSID:E060AFE6-5EFF-4830-B7F0-093ECC08EF37" codebase=http://www.rubylong/webreport/griectl.cab#Version=5.6.11.1118  width="100%" height="100%" id="ReportViewer" VIEWASTEXT>'+                                '<param name="ReportURL" value="http://www.rubylong.cn/WebReport/grf/1a.grf">'+                                '<param name="DataURL" value="http://www.rubylong.cn/WebReport/data/xmlCustomer.txt">'+                                '<param name="Resortable"  value="true">'+                                '</OBJECT> ',                                null);            var report=document.getElementById('ReportViewer');            report.attachEvent('SelectionCellChange',function(OldRow, OldCol){                var city =report.report.fieldByName('CompanyName').asstring;               // alert(city);            }                              );                        report.attachEvent('ContentCellDblClick',function(Sender){                alert(Sender.name);            });                    }    }});