asp.net ajax的this.get_element()在我声明的函数中不起作用

时间:2012-08-31 10:45:12

标签: asp.net asp.net-ajax

我尝试通过this.get_element()访问我自己的函数中的元素,但它不起作用。

    Type.registerNamespace("LabelTimeExtender1");

LabelTimeExtender1.ClientBehavior1 = function(element) {
LabelTimeExtender1.ClientBehavior1.initializeBase(this, [element]);
var testelement=this.get_element();
var timestamp= this.get_element().attributes['TimeStamp'].value;
alert("in constructor");

},

 LabelTimeExtender1.ClientBehavior1.prototype = {
 initialize: function() {
    LabelTimeExtender1.ClientBehavior1.callBaseMethod(this, 'initialize');
    setInterval (this.timer,1000);
    alert("after");

},
dispose: function() {        
    //Add custom dispose actions here
    LabelTimeExtender1.ClientBehavior1.callBaseMethod(this, 'dispose');
},
timer: function(){

debugger;
            var date= new Date(this.timestamp);
            var datenow= new Date ();
            this._element.innerText=" ";
              if(date.getUTCFullYear<datenow.getUTCFullYear)
            {
             var myelement= this.get_element();
             myelement .innerHTML= date.getUTCFullYear.toString();
            }
            if(date.getUTCMonth<datenow.getUTCMonth)
            {
            this.get_element().innerHTML=date.getUTCMonth.toString();
            }
            if(date.getUTCDay<datenow.getUTCDay)
            {
            this.get_element().innerHTML=date.getUTCDay.toString();
            }
            if(date.getUTCHours <datenow.getUTCHours )
            {
             this.get_element().innerHTML=date.getUTCHours .toString();
            }
            if(date.getUTCMinutes<datenow.getUTCMinutes)
            {
            this.get_element().innerHTML=date.getUTCMinutes.toString();
            }


}




}
 LabelTimeExtender1.ClientBehavior1.registerClass('LabelTimeExtender1.ClientBehavior1',   Sys.UI.Behavior);

  if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

这里我试图访问自定义属性'TimeStamp'并计算时间并分配给要显示的标签。

1 个答案:

答案 0 :(得分:2)

尝试通过委托调用您的函数。然后您对[this]关键字

没有问题

类似的东西:

     setInterval (Function.createDelegate(this, this.timer),1000)